4.0 KiB
layout | page_title | sidebar_current | description |
---|---|---|---|
postgresql | PostgreSQL: postgresql_database | docs-postgresql-resource-postgresql_database | Creates and manages a database on a PostgreSQL server. |
postgresql_database
The postgresql_database
resource creates and manages a database instance on
a PostgreSQL server.
Usage
resource "postgresql_database" "my_db" {
name = "my_db"
owner = "my_role"
template = "template0"
collation = "C"
connection_limit = -1
allow_connections = true
}
Argument Reference
-
name
- (Required) The name of the database. Must be unique on the PostgreSQL server instance where it is configured. -
owner
- (Optional) The role name of the user who will own the database, orDEFAULT
to use the default (namely, the user executing the command). To create a database owned by another role or to change the owner of an existing database, you must be a direct or indirect member of the specified role, or the username in the provider is a superuser. -
tablespace_name
- (Optional) The name of the tablespace that will be associated with the database, orDEFAULT
to use the template database's tablespace. This tablespace will be the default tablespace used for objects created in this database. -
connection_limit
- (Optional) How many concurrent connections can be made to this database.-1
(the default) means no limit. -
allow_connections
- (Optional) Iffalse
then no one can connect to this database. The default istrue
, allowing connections (except as restricted by other mechanisms, such asGRANT
orREVOKE CONNECT
). -
is_template
- (Optional) Iftrue
, then this database can be cloned by any user withCREATEDB
privileges; iffalse
(the default), then only superusers or the owner of the database can clone it. -
template
- (Optional) The name of the template database from which to create the database, orDEFAULT
to use the default template (template0
). NOTE: the default in Terraform istemplate0
, nottemplate1
. Changing this value will force the creation of a new resource as this value can only be changed when a database is created. -
encoding
- (Optional) Character set encoding to use in the database. Specify a string constant (e.g.UTF8
orSQL_ASCII
), or an integer encoding number. If unset or set to an empty string the default encoding is set toUTF8
. If set toDEFAULT
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. -
lc_collate
- (Optional) Collation order (LC_COLLATE
) to use in the database. This affects the sort order applied to strings, e.g. in queries withORDER BY
, as well as the order used in indexes on text columns. If unset or set to an empty string the default collation is set toC
. If set toDEFAULT
Terraform will use the same collation order as the specifiedtemplate
database. Changing this value will force the creation of a new resource as this value can only be changed when a database is created. -
lc_ctype
- (Optional) Character classification (LC_CTYPE
) to use in the database. This affects the categorization of characters, e.g. lower, upper and digit. If unset or set to an empty string the default character classification is set toC
. If set toDEFAULT
Terraform will use the character classification of the specifiedtemplate
database. Changing this value will force the creation of a new resource as this value can only be changed when a database is created.
Import Example
postgresql_database
supports importing resources. Supposing the following
Terraform:
provider "postgresql" {
alias = "admindb"
}
resource "postgresql_database" "db1" {
provider = "postgresql.admindb"
name = "db1"
}
It is possible to import a postgresql_database
resource with the following
command:
$ terraform import postgresql_database.testdb1 testdb1