设置生产postgres(createdb权限)

时间:2020-05-31 19:01:28

标签: postgresql

我正在DigitalOcean上设置postgres。我已经设置了PG环境。 9显然是已编辑的数据。为了促进ssl连接,存在~/.postgresql/root.crt

# env | grep PG
PGPORT=99999
PGPASSWORD=9999999999999
PGSSLMODE=require
PGUSER=doadmin
PGDATABASE=auth_service_prod
PGHOST=private-db-postgresql-sfo9-99999-do-user-9999999-9.a.db.ondigitalocean.com

调用createdb时失败:

# createdb
createdb: could not connect to database template1: FATAL:  pg_hba.conf rejects connection for host "10.999.9.99", user "doadmin", database "template1", SSL on
但是,

可以连接到psql。我对将postgres配置为允许doadmin创建数据库的了解还不够,但是希望这里有一些有用的信息:

# psql
psql (11.7 (Debian 11.7-0+deb10u1), server 11.8)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

auth_service_prod=> \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 _dodb     | Superuser, Replication                                     | {}
 doadmin   | Create role, Create DB, Replication, Bypass RLS            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

auth_service_prod=> \l
                                      List of databases
       Name        |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-------------------+----------+----------+-------------+-------------+-----------------------
 _dodb             | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 auth_service_prod | doadmin  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 defaultdb         | doadmin  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0         | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                   |          |          |             |             | postgres=CTc/postgres
 template1         | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                   |          |          |             |             | postgres=CTc/postgres
(5 rows)

1 个答案:

答案 0 :(得分:0)

很显然,DigitalOcean不允许来自postgres的createdb。我删除了创建数据库的代码,并从其GUI“手动”创建了它们。该应用程序现在仅负责管理架构,而不是数据库。