github.com/nbering/terraform@v0.8.5-0.20170113232247-453f670684b5/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  
    30  ## Argument Reference
    31  
    32  * `name` - (Required) The name of the database. Must be unique on the PostgreSQL
    33    server instance where it is configured.
    34  
    35  * `owner` - (Optional) The role name of the user who will own the database, or
    36    `DEFAULT` to use the default (namely, the user executing the command). To
    37    create a database owned by another role or to change the owner of an existing
    38    database, you must be a direct or indirect member of the specified role, or
    39    the username in the provider is a superuser.
    40  
    41  * `tablespace_name` - (Optional) The name of the tablespace that will be
    42    associated with the database, or `DEFAULT` to use the template database's
    43    tablespace.  This tablespace will be the default tablespace used for objects
    44    created in this database.
    45  
    46  * `connection_limit` - (Optional) How many concurrent connections can be
    47    established to this database. `-1` (the default) means no limit.
    48  
    49  * `allow_connections` - (Optional) If `false` then no one can connect to this
    50    database. The default is `true`, allowing connections (except as restricted by
    51    other mechanisms, such as `GRANT` or `REVOKE CONNECT`).
    52  
    53  * `is_template` - (Optional) If `true`, then this database can be cloned by any
    54    user with `CREATEDB` privileges; if `false` (the default), then only
    55    superusers or the owner of the database can clone it.
    56  
    57  * `template` - (Optional) The name of the template database from which to create
    58    the database, or `DEFAULT` to use the default template (`template0`).  NOTE:
    59    the default in Terraform is `template0`, not `template1`.  Changing this value
    60    will force the creation of a new resource as this value can only be changed
    61    when a database is created.
    62  
    63  * `encoding` - (Optional) Character set encoding to use in the database.
    64    Specify a string constant (e.g. `UTF8` or `SQL_ASCII`), or an integer encoding
    65    number.  If unset or set to an empty string the default encoding is set to
    66    `UTF8`.  If set to `DEFAULT` Terraform will use the same encoding as the
    67    template database.  Changing this value will force the creation of a new
    68    resource as this value can only be changed when a database is created.
    69  
    70  * `lc_collate` - (Optional) Collation order (`LC_COLLATE`) to use in the
    71    database.  This affects the sort order applied to strings, e.g. in queries
    72    with `ORDER BY`, as well as the order used in indexes on text columns. If
    73    unset or set to an empty string the default collation is set to `C`.  If set
    74    to `DEFAULT` Terraform will use the same collation order as the specified
    75    `template` database.  Changing this value will force the creation of a new
    76    resource as this value can only be changed when a database is created.
    77  
    78  * `lc_ctype` - (Optional) Character classification (`LC_CTYPE`) to use in the
    79    database. This affects the categorization of characters, e.g. lower, upper and
    80    digit. If unset or set to an empty string the default character classification
    81    is set to `C`.  If set to `DEFAULT` Terraform will use the character
    82    classification of the specified `template` database.  Changing this value will
    83    force the creation of a new resource as this value can only be changed when a
    84    database is created.
    85  
    86  ## Import Example
    87  
    88  `postgresql_database` supports importing resources.  Supposing the following
    89  Terraform:
    90  
    91  ```
    92  provider "postgresql" {
    93    alias = "admindb"
    94  }
    95  
    96  resource "postgresql_database" "db1" {
    97    provider = "postgresql.admindb"
    98  
    99    name = "testdb1"
   100  }
   101  ```
   102  
   103  It is possible to import a `postgresql_database` resource with the following
   104  command:
   105  
   106  ```
   107  $ terraform import postgresql_database.db1 testdb1
   108  ```
   109  
   110  Where `testdb1` is the name of the database to import and
   111  `postgresql_database.db1` is the name of the resource whose state will be
   112  populated as a result of the command.