Skip to content
This repository has been archived by the owner on Nov 14, 2020. It is now read-only.

postgresql_database: DEFAULT value does not work as documented for encoding #9

Closed
dohoangkhiem opened this issue Jul 3, 2017 · 2 comments
Assignees
Labels

Comments

@dohoangkhiem
Copy link

dohoangkhiem commented Jul 3, 2017

According to https://www.terraform.io/docs/providers/postgresql/r/postgresql_database.html#encoding

encoding - (Optional) Character set encoding to use in the database. Specify a string constant (e.g. UTF8 or SQL_ASCII), or an integer encoding number. If unset or set to an empty string the default encoding is set to UTF8. If set to DEFAULT Terraform will use the same encoding as the template database. Changing this value will force the creation of a new resource as this value can only be changed when a database is created.

However setting the encoding to DEFAULT value just causes an error

resource "postgresql_database" "test1" {
  provider = "postgresql.test1"
  name = "test1"
  template = "template1" # "template0"
  encoding =  "DEFAULT" # "UTF8"
  lc_collate = "DEFAULT" # "en_US.UTF-8"
  lc_ctype = "DEFAULT" # "en_US.UTF-8"
* postgresql_database.test1: Error creating database "test1": pq: DEFAULT is not a valid encoding name

How do we use template1 with postgresql_database resource with default encoding from the template?

Terraform version is 0.9.8

@grubernaut grubernaut added the bug label Jul 3, 2017
sean- added a commit that referenced this issue Jul 9, 2017
Use of `DEFAULT` is problematic because the user is specifying a value which
defeats the Terraform `Computed` resource attribute.  A byproduct of this
is that use of `DEFAULT` can not be used without adding lifecycle attribute
otherwise the plan never converges.

```
resource "postgresql_database" "pg_default_opts" {
  lifecycle {
    ignore_changes = [
      "template",
      "encoding",
      "lc_collate",
      "lc_ctype",
      "tablespace_name",
    ]
  }
  # snip
}
```

Fixes: #9
@sean-
Copy link
Contributor

sean- commented Jul 9, 2017

@dohoangkhiem , see if #10 fixes your issue. Please note the comment about lifecycle.

sean- added a commit that referenced this issue Jul 10, 2017
…connection handling.

As a necessary byproduct of supporting older versions of PostgreSQL
where shared_buffer handling is different, it was also necessary to
fix the connection handling.  Previously the provider would check out
as many connections as it wanted and would basically never free them
or return them back to the sql.DB pool.  After this change each query
performs the appropriate Exec and returns the connection back to the
pool.  As a result, all tests pass and only ~2 connections are opened
at a time.  I've set a default max_connections limit in the provider
of 4 but am allowing users to change this as they see fit in the
provider config.

Fixes: #8 #9

This PR pulled in the fix from #10 as it was required to support PostgreSQL 9.2..
@cyrilgdn
Copy link
Contributor

@dohoangkhiem Without answer, I allow myself to close this issue.

Feel free to reopen it if needed after having check if it's not fixed (see previous comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants