2015-10-27 11:04:19 +01:00
---
layout: "postgresql"
page_title: "Provider: PostgreSQL"
sidebar_current: "docs-postgresql-index"
description: |-
A provider for PostgreSQL Server.
---
# PostgreSQL Provider
The PostgreSQL provider gives the ability to deploy and configure resources in a PostgreSQL server.
Use the navigation to the left to read about the available resources.
## Usage
2017-04-17 12:17:54 +02:00
```hcl
2015-10-27 11:04:19 +01:00
provider "postgresql" {
2017-02-18 23:48:50 +01:00
host = "postgres_server_ip"
port = 5432
database = "postgres"
username = "postgres_user"
password = "postgres_password"
sslmode = "require"
2016-11-28 17:52:10 +01:00
connect_timeout = 15
2015-10-27 11:04:19 +01:00
}
```
Configuring multiple servers can be done by specifying the alias option.
2017-04-17 12:17:54 +02:00
```hcl
2015-10-27 11:04:19 +01:00
provider "postgresql" {
2017-02-18 23:48:50 +01:00
alias = "pg1"
host = "postgres_server_ip1"
2015-10-27 11:04:19 +01:00
username = "postgres_user1"
password = "postgres_password1"
}
provider "postgresql" {
2017-02-18 23:48:50 +01:00
alias = "pg2"
host = "postgres_server_ip2"
2015-10-27 11:04:19 +01:00
username = "postgres_user2"
password = "postgres_password2"
}
resource "postgresql_database" "my_db1" {
provider = "postgresql.pg1"
2017-02-18 23:48:50 +01:00
name = "my_db1"
2015-10-27 11:04:19 +01:00
}
2017-02-18 23:48:50 +01:00
2015-10-27 11:04:19 +01:00
resource "postgresql_database" "my_db2" {
provider = "postgresql.pg2"
2017-02-18 23:48:50 +01:00
name = "my_db2"
2015-10-27 11:04:19 +01:00
}
```
## Argument Reference
The following arguments are supported:
* `host` - (Required) The address for the postgresql server connection.
2016-04-17 17:32:02 +02:00
* `port` - (Optional) The port for the postgresql server connection. The default is `5432` .
2016-11-06 09:27:51 +01:00
* `database` - (Optional) Database to connect to. The default is `postgres` .
2015-10-27 11:04:19 +01:00
* `username` - (Required) Username for the server connection.
2016-04-04 17:40:28 +02:00
* `password` - (Optional) Password for the server connection.
2016-11-06 09:27:51 +01:00
* `sslmode` - (Optional) Set the priority for an SSL connection to the server.
2016-11-06 09:44:57 +01:00
Valid values for `sslmode` are (note: `prefer` is not supported by Go's
[`lib/pq` ](https://godoc.org/github.com/lib/pq )):
* disable - No SSL
* require - Always SSL (the default, also skip verification)
* verify-ca - Always SSL (verify that the certificate presented by the server was signed by a trusted CA)
* verify-full - Always SSL (verify that the certification presented by the server was signed by a trusted CA and the server host name matches the one in the certificate)
Additional information on the options and their implications can be seen
[in the `libpq(3)` SSL guide ](http://www.postgresql.org/docs/current/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION ).
2016-11-06 09:49:37 +01:00
* `connect_timeout` - (Optional) Maximum wait for connection, in seconds. The
default is `180s` . Zero or not specified means wait indefinitely.