在Arizona部署上获取内部服务器错误

时间:2019-07-06 15:27:18

标签: docker pgadmin heroku-postgres prisma prisma-graphql

我在Heroku上有一个Postgres数据库,通过执行prisma deploy部署数据模型时,经常会产生以下错误。

ERROR: Whoops. Looks like an internal server error. Search your server logs for request ID: local:cjxrmcnpx00hq0692zuwttqwv

{
 "data": {
   "addProject": null
 },
 "errors": [
   {
     "message": "Whoops. Looks like an internal server error. Search your server logs for request ID: local:cjxrmcnpx00hq0692zuwttqwv",
     "path": [
       "addProject"
     ],
     "locations": [
       {
         "line": 2,
         "column": 9
       }
     ],
     "requestId": "local:cjxrmcnpx00hq0692zuwttqwv"
   }
 ],
 "status": 200
}

在检查Docker日志时,我看到了这个错误:

Jul 14, 2019 12:18:34 PM org.postgresql.Driver connect
prisma_1  | SEVERE: Connection error: 
prisma_1  | org.postgresql.util.PSQLException: FATAL: too many connections for role "bcueventxumaik"  
prisma_1  |     at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
prisma_1  |     at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
prisma_1  |     at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)        
prisma_1  |     at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
prisma_1  |     at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
prisma_1  |     at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
prisma_1  |     at org.postgresql.Driver.makeConnection(Driver.java:452)
prisma_1  |     at org.postgresql.Driver.connect(Driver.java:254)
prisma_1  |     at slick.jdbc.DriverDataSource.getConnection(DriverDataSource.scala:101)
prisma_1  |     at slick.jdbc.DataSourceJdbcDataSource.createConnection(JdbcDataSource.scala:68)      
prisma_1  |     at slick.jdbc.JdbcBackend$BaseSession.<init>(JdbcBackend.scala:453)
prisma_1  |     at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:46)
prisma_1  |     at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:37)
prisma_1  |     at slick.basic.BasicBackend$DatabaseDef.acquireSession(BasicBackend.scala:249)        
prisma_1  |     at slick.basic.BasicBackend$DatabaseDef.acquireSession$(BasicBackend.scala:248)       
prisma_1  |     at slick.jdbc.JdbcBackend$DatabaseDef.acquireSession(JdbcBackend.scala:37)
prisma_1  |     at slick.basic.BasicBackend$DatabaseDef$$anon$2.run(BasicBackend.scala:274)
prisma_1  |     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)    
prisma_1  |     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)    
prisma_1  |     at java.lang.Thread.run(Thread.java:748)
prisma_1  |
prisma_1  | Exception in thread "main" org.postgresql.util.PSQLException: FATAL: too many connections 
prisma_1  |     at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)prisma_1  |     at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)prisma_1  |     at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
prisma_1  |     at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)prisma_1  |     at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
prisma_1  |     at org.postgresql.Driver.makeConnection(Driver.java:452)
prisma_1  |     at org.postgresql.Driver.connect(Driver.java:254)prisma_1  |     at slick.jdbc.DriverDataSource.getConnection(DriverDataSource.scala:101)
prisma_1  |     at slick.jdbc.DataSourceJdbcDataSource.createConnection(JdbcDataSource.scala:68)
prisma_1  |     at slick.jdbc.JdbcBackend$BaseSession.<init>(JdbcBackend.scala:453)
prisma_1  |     at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:46)
prisma_1  |     at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:37)
prisma_1  |     at slick.basic.BasicBackend$DatabaseDef.acquireSession(BasicBackend.scala:249)
prisma_1  |     at slick.basic.BasicBackend$DatabaseDef.acquireSession$(BasicBackend.scala:248)
prisma_1  |     at slick.jdbc.JdbcBackend$DatabaseDef.acquireSession(JdbcBackend.scala:37)
prisma_1  |     at slick.basic.BasicBackend$DatabaseDef$$anon$2.run(BasicBackend.scala:274)
prisma_1  |     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
prisma_1  |     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
prisma_1  |     at java.lang.Thread.run(Thread.java:748)
prisma_prisma_1 exited with code 1

错误是说连接太多,但是我仅从一个终端触发 prisma deploy ,同时我可以使用PgAdmin4连接到数据库。而且,由于我能够从容器内部对数据库执行ping操作,因此数据库似乎可以完美访问。

PS。较早地在运行docker logs -f processid时更新了docker日志,我得到了较旧的日志,但是现在再次使用docker-compose up构建容器时,我得到了最新的日志

2 个答案:

答案 0 :(得分:0)

由于错误明确指出与数据库的连接过多。因此,我们需要调查有多少个连接,谁在创建它们以及为什么创建它们。为了限制使用者或增加可用连接的数量。

首先,我们可以使用heroku CLI检查已使用和可用的连接数量:

$ heroku pg:info

=== DATABASE_URL
Plan:                  Private 2
Status:                Available
HA Status:             Available
Data Size:             2.23 GB
Tables:                83
PG Version:            10.1
Connections:           26/400
Connection Pooling:    Available

有关如何调查heroku postgres数据库的更多信息,请参见:https://devcenter.heroku.com/articles/heroku-postgresql#pg-info

要进一步调查谁连接到您的数据库,可以使用psql或pgAdmin。如果使用pgAdmin,则可以选择数据库,单击仪表板选项卡,然后选择页面底部的服务器活动面板,其中显示了所有已连接的会话。如果使用psql,则可以编写如下选择:

SELECT pid as process_id, 
       usename as username, 
       datname as database_name, 
       client_addr as client_address, 
       application_name,
       backend_start,
       state,
  FROM pg_stat_activity;

有关如何查看的详细信息:https://dataedo.com/kb/query/postgresql/list-database-sessions

现在,您可能已经确定了谁在创建与数据库的连接,并且可以限制客户端使用的数据库更少(或增加可用数据库连接的数量)。

数据库连接的一个可能的使用者当然是棱镜服务器本身。幸运的是,prisma配置提供了限制数据库连接的设置。

  

PRISMA_CONFIG中的connectionLimit属性确定   Prisma服务将要使用的数据库连接。

您可以在此处了解更多信息:https://www.prisma.io/docs/prisma-server/database-connector-POSTGRES-jgfr/#managing-database-connections

如果您使用heroku在您的prisma服务器上运行docker容器,则PRISMA_CONFIG可能如下所示:

port: $PORT
managementApiSecret: ${PRISMA_MANAGEMENT_API_SECRET}
databases:
  default:
    connector: postgres
    migrations: true
    connectionLimit: 2
    uri: ${DATABASE_URL}?ssl=1  

我希望这种结构化的方法能有所帮助。让我知道是否需要进一步说明。如果是这样,请提供有关现有数据库连接性质的详细信息。

答案 1 :(得分:0)

运行此命令

docker logs <YOUR_PRISMA_CONTAINER_NAME>