github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/postgresql/r/postgresql_database.html.markdown (about) 1 --- 2 layout: "postgresql" 3 page_title: "PostgreSQL: postgresql_database" 4 sidebar_current: "docs-postgresql-resource-postgresql_database" 5 description: |- 6 Creates and manages a database on a PostgreSQL server. 7 --- 8 9 # postgresql\_database 10 11 The ``postgresql_database`` resource creates and manages [database 12 objects](https://www.postgresql.org/docs/current/static/managing-databases.html) 13 within a PostgreSQL server instance. 14 15 16 ## Usage 17 18 ``` 19 resource "postgresql_database" "my_db" { 20 name = "my_db" 21 owner = "my_role" 22 template = "template0" 23 collation = "C" 24 connection_limit = -1 25 allow_connections = true 26 } 27 ``` 28 29 ## Argument Reference 30 31 * `name` - (Required) The name of the database. Must be unique on the PostgreSQL 32 server instance where it is configured. 33 34 * `owner` - (Optional) The role name of the user who will own the database, or 35 `DEFAULT` to use the default (namely, the user executing the command). To 36 create a database owned by another role or to change the owner of an existing 37 database, you must be a direct or indirect member of the specified role, or 38 the username in the provider is a superuser. 39 40 * `tablespace_name` - (Optional) The name of the tablespace that will be 41 associated with the database, or `DEFAULT` to use the template database's 42 tablespace. This tablespace will be the default tablespace used for objects 43 created in this database. 44 45 * `connection_limit` - (Optional) How many concurrent connections can be 46 established to this database. `-1` (the default) means no limit. 47 48 * `allow_connections` - (Optional) If `false` then no one can connect to this 49 database. The default is `true`, allowing connections (except as restricted by 50 other mechanisms, such as `GRANT` or `REVOKE CONNECT`). 51 52 * `is_template` - (Optional) If `true`, then this database can be cloned by any 53 user with `CREATEDB` privileges; if `false` (the default), then only 54 superusers or the owner of the database can clone it. 55 56 * `template` - (Optional) The name of the template database from which to create 57 the database, or `DEFAULT` to use the default template (`template0`). NOTE: 58 the default in Terraform is `template0`, not `template1`. Changing this value 59 will force the creation of a new resource as this value can only be changed 60 when a database is created. 61 62 * `encoding` - (Optional) Character set encoding to use in the database. 63 Specify a string constant (e.g. `UTF8` or `SQL_ASCII`), or an integer encoding 64 number. If unset or set to an empty string the default encoding is set to 65 `UTF8`. If set to `DEFAULT` Terraform will use the same encoding as the 66 template database. Changing this value will force the creation of a new 67 resource as this value can only be changed when a database is created. 68 69 * `lc_collate` - (Optional) Collation order (`LC_COLLATE`) to use in the 70 database. This affects the sort order applied to strings, e.g. in queries 71 with `ORDER BY`, as well as the order used in indexes on text columns. If 72 unset or set to an empty string the default collation is set to `C`. If set 73 to `DEFAULT` Terraform will use the same collation order as the specified 74 `template` database. Changing this value will force the creation of a new 75 resource as this value can only be changed when a database is created. 76 77 * `lc_ctype` - (Optional) Character classification (`LC_CTYPE`) to use in the 78 database. This affects the categorization of characters, e.g. lower, upper and 79 digit. If unset or set to an empty string the default character classification 80 is set to `C`. If set to `DEFAULT` Terraform will use the character 81 classification of the specified `template` database. Changing this value will 82 force the creation of a new resource as this value can only be changed when a 83 database is created. 84 85 ## Import Example 86 87 `postgresql_database` supports importing resources. Supposing the following 88 Terraform: 89 90 ``` 91 provider "postgresql" { 92 alias = "admindb" 93 } 94 95 resource "postgresql_database" "db1" { 96 provider = "postgresql.admindb" 97 98 name = "testdb1" 99 } 100 ``` 101 102 It is possible to import a `postgresql_database` resource with the following 103 command: 104 105 ``` 106 $ terraform import postgresql_database.db1 testdb1 107 ``` 108 109 Where `testdb1` is the name of the database to import and 110 `postgresql_database.db1` is the name of the resource whose state will be 111 populated as a result of the command.