Pyramid Postgresql连接问题

2024-06-16 20:29:45 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我一直在使用sqlite3来访问sqlalchemy数据库。我开发了一个pyramidweb框架,sqlite3已经开始工作了。但是,我希望不再使用sqlite3,而是将postgresql用于数据库。我是新手,我想弄清楚我是否遗漏了一步。在

我在下载psycopg2(将其添加到设置.py)正在将development.ini文件更改为:
sqlalchemy.url = sqlite:////Users/ack/code/venv/NotssDB/notssdb/notssdb
收件人:
sqlalchemy.url = postgresql://ack:password@localhost:5432/notssdb
我使用macosx通过this site安装了postgres。在

也就是说,当我启动应用程序pserve development.ini时,数据库没有连接或加载。当我使用sqliteurl时,数据库连接。在

我可能会错过什么?在

开发.ini 在金字塔中:

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

postgresql.conf

^{pr2}$

postgres服务器日志:

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

我要换postgres config file吗?(A stacks question也指它)。。。我在^{中看到了这个:

# "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

通过终端,我可以连接到postgres上的数据库:

psql -h localhost -d notssdb -p 5432

新的

postgresql server将自动启动

如何启动金字塔应用程序:

$ 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

正在检查服务器:

$  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"

Tags: 数据库localhosthostserversqlalchemypostgresqllocalpostgres
1条回答
网友
1楼 · 发布于 2024-06-16 20:29:45

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

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

这里的Port参数是pserve listen Port,改成8000左右。在

相关问题 更多 >