金字塔Postgresql连接问题

时间:2015-10-15 19:59:10

标签: python postgresql sqlalchemy pyramid

在金字塔中从SQLITE3迁移到Postgresql(psql(PostgreSQL)9.4.5)

我一直在使用sqlite3来访问sqlalchemy数据库。我开发了一个pyramid Web框架,sqlite3一直在工作。但是,我希望不再使用sqlite3而是使用postgresql作为数据库。我是新手,我想弄清楚我是否错过了一步。

我在psycopg2下载了development.ini(将其添加到setup.py),从而更改了sqlalchemy.url = sqlite:////Users/ack/code/venv/NotssDB/notssdb/notssdb文件:
sqlalchemy.url = postgresql://ack:password@localhost:5432/notssdb
到:
pserve development.ini
我使用mac osx通过this tutorial安装了postgres。

据说,当我启动应用程序sqlite时...数据库没有连接或加载。当我使用sqlalchemy.url = postgresql://ack:password@localhost:5432/notssdb # By default, the toolbar only appears for clients from IP addresses # '127.0.0.1' and '::1'. # debugtoolbar.hosts = 127.0.0.1 ::1 ### # wsgi server configuration ### [server:main] use = egg:waitress#main host = 0.0.0.0 port = 5432 url时,数据库会连接。

我可能会缺少什么?

development.ini 在金字塔中:

postgresql.conf

# - Connection Settings - #listen_addresses = 'localhost' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) #port = 5432 # (change requires restart) max_connections = 100 # (change requires restart)

LOG:  invalid length of startup packet
LOG:  invalid length of startup packet

postgres服务器日志:

pg_hba.conf

我是否需要更改this site? (postgres config file也指它...)我在# "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 0.0.0.0/0 trust host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust # Allow replication connections from localhost, by a user with the # replication privilege. #local replication ack trust #host replication ack 127.0.0.1/32 trust #host replication ack ::1/128 trust 中看到了这一点:

psql -h localhost -d notssdb -p 5432

使用终端,这将我连接到postgres上的数据库:

$ python setup.py develop #installs packages 
$ initialize_notssweb_db development.ini # --db Session--
$ pserve development.ini  #terminal: --db Session-- Starting server in PID 3501. serving on http://0.0.0.0:5432

postgresql服务器自动启动

我如何启动金字塔应用

$  pg_ctl -D /usr/local/var/postgres status
pg_ctl: server is running (PID: 701)
/usr/local/Cellar/postgresql/9.4.5/bin/postgres "-D" "/usr/local/var/postgres" "-r" "/usr/local/var/postgres/server.log"

检查服务器:

Console.KeyAvalible

1 个答案:

答案 0 :(得分:2)

不确定这是否是唯一的问题,但看起来你有端口冲突。您尝试在同一端口上启动金字塔应用程序(通过pserve)默认情况下postgresql侦听(5432)。

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 5432

此处的端口参数用于pserve监听端口,将其更改为8000或其他内容。