# Postgres DB init fails in Azure

**URL:** <https://discuss.hashicorp.com/t/postgres-db-init-fails-in-azure/20862>\
**Category:** Boundary\
**Created:** [February 11, 2021, 8:55pm UTC](https://discuss.hashicorp.com/t/postgres-db-init-fails-in-azure/20862 "2021-02-11T20:55:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ned1313](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ned1313/32/4853_2.png) [@ned1313](https://discuss.hashicorp.com/u/ned1313)\
**Post date:** [February 11, 2021, 8:55pm UTC](https://discuss.hashicorp.com/t/postgres-db-init-fails-in-azure/20862/1 "2021-02-11T20:55:01Z")

</div>

I’m trying to get Boundary set up in Azure using Azure PostgreSQL and an Azure VM. On the controller I am running:

```auto
/usr/bin/boundary database init -skip-auth-method-creation -skip-host-resources-creation -skip-scopes-creation -skip-target-creation -config 
/etc/boundary-controller.hcl

```

And I get the error:

```auto
Error running database migrations: schema.(Manager).RollForward: schema.(Manager).runMigrations: postgres.(Postgres).Run: migration failed, on line 0: 
-- This series of expressions fixes the primary key on the server table
alter table session
  drop constraint session_server_id_server_type_fkey;
alter table server
  drop constraint server_pkey;
alter table server
  drop column name;
alter table server
  add primary key (private_id);
alter table server
  add constraint server_id_must_not_be_empty
  check(length(trim(private_id)) > 0);
alter table session
  add constraint session_server_id_fkey
  foreign key (server_id)
  references server(private_id)
  on delete set null
  on update cascade;

create domain wt_bexprfilter as text
check(
  value is null
    or
    (
      length(trim(value)) > 0
        and
      length(trim(value)) <= 2048
    )
);
comment on domain wt_bexprfilter is
  'Text field with constraints for go-bexpr filters';

-- Add the worker filter to the target_tcp table and session table
alter table target_tcp
  add column worker_filter wt_bexprfilter;
alter table session
  add column worker_filter wt_bexprfilter;

-- Replace the immutable columns trigger from 50 to add worker_filter
drop trigger immutable_columns on session;
create trigger immutable_columns
  before update on session
    for each row execute procedure immutable_columns('public_id', 'certificate', 'expiration_time', 'connection_limit', 'create_time', 'endpoint', 'worker_filter');     

-- Replaces the view created in 41 to include worker_filter
drop view target_all_subtypes;
create view target_all_subtypes
as
select
  public_id,
  scope_id,
  name,
  description,
  default_port,
  session_max_seconds,
  session_connection_limit,
  version,
  create_time,
  update_time,
  worker_filter,
  'tcp' as type
from target_tcp;

-- Replaces the view created in 50 to include worker_filter
drop view session_with_state;
create view session_with_state as
  select
    s.public_id,
    s.user_id,
    s.host_id,
    s.server_id,
    s.server_type,
    s.target_id,
    s.host_set_id,
    s.auth_token_id,
    s.scope_id,
    s.certificate,
    s.expiration_time,
    s.connection_limit,
    s.tofu_token,
    s.key_id,
    s.termination_reason,
    s.version,
    s.create_time,
    s.update_time,
    s.endpoint,
    s.worker_filter,
    ss.state,
    ss.previous_end_time,
    ss.start_time,
    ss.end_time
  from
    session s,
    session_state ss
  where
    s.public_id = ss.session_id;

create domain wt_tagpair as text
check(
  value is not null
    and
  length(trim(value)) > 0
    and
  length(trim(value)) <= 512
    and
  lower(trim(value)) = value
);
comment on domain wt_tagpair is
  'Text field with constraints for key/value pairs';

create table server_tag (
  server_id text
    references server(private_id)
    on delete cascade
    on update cascade,
  key wt_tagpair,
  value wt_tagpair,
  primary key(server_id, key, value)
);
: unknown: error #0: pq: constraint "session_server_id_server_type_fkey" of relation "session" does not exist

```

It looks like Boundary is trying to run a database migration, but this is a clean install with no existing db to migrate. Any ideas on what is going on here?

For reference, I am running Boundary 0.1.5 and Postgres 11.6.

---

<div class="post-metadata">

**Author:** ![ned1313](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ned1313/32/4853_2.png) [@ned1313](https://discuss.hashicorp.com/u/ned1313)\
**Post date:** [February 11, 2021, 9:18pm UTC](https://discuss.hashicorp.com/t/postgres-db-init-fails-in-azure/20862/2 "2021-02-11T21:18:55Z")

</div>

FYI - I tried the same with Boundary 0.1.4 and the database initialized without issue.

---

<div class="post-metadata">

**Author:** ![jeff](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jeff/32/12882_2.png) [@jeff](https://discuss.hashicorp.com/u/jeff)\
**Post date:** [February 16, 2021, 4:48pm UTC](https://discuss.hashicorp.com/t/postgres-db-init-fails-in-azure/20862/3 "2021-02-16T16:48:18Z")

</div>

The drop there is using Postgres default constraint naming. It’s possible that it’s different in Postgres 11, or different on Azure. We’ll try to figure out the issue here – in the mean time, any chance you can try with Postgres 12?

---

<div class="post-metadata">

**Author:** ![jeff](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jeff/32/12882_2.png) [@jeff](https://discuss.hashicorp.com/u/jeff)\
**Post date:** [February 16, 2021, 4:52pm UTC](https://discuss.hashicorp.com/t/postgres-db-init-fails-in-azure/20862/4 "2021-02-16T16:52:23Z")

</div>

I just tested – I can confirm this is a Postgres 11 vs 12 issue. We’ll have to discuss internally how to address it, or if we will want to standardize on Postgres 12.

---

<div class="post-metadata">

**Author:** ![jeff](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jeff/32/12882_2.png) [@jeff](https://discuss.hashicorp.com/u/jeff)\
**Post date:** [February 16, 2021, 6:55pm UTC](https://discuss.hashicorp.com/t/postgres-db-init-fails-in-azure/20862/5 "2021-02-16T18:55:52Z")

</div>

We’re going to spin a 0.1.7 today to fix this issue.

---

<div class="post-metadata">

**Author:** ![ned1313](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ned1313/32/4853_2.png) [@ned1313](https://discuss.hashicorp.com/u/ned1313)\
**Post date:** [February 16, 2021, 8:30pm UTC](https://discuss.hashicorp.com/t/postgres-db-init-fails-in-azure/20862/6 "2021-02-16T20:30:07Z")

</div>

Awesome, thanks Jeff! I’ll take it for a spin.
