【问题标题】:Pyramid Postgresql Connection IssuePyramid Postgresql 连接问题
【发布时间】:2016-01-14 10:30:03
【问题描述】:

在 Pyramid 中从 SQLITE3 迁移到 Postgresql (psql (PostgreSQL) 9.4.5)

我一直在使用sqlite3 访问sqlalchemy 数据库。我开发了一个pyramid web 框架,并且 sqlite3 一直在工作。但是,我想放弃使用sqlite3,而是使用postgresql 作为数据库。我对此并不陌生,并试图弄清楚我是否错过了一步。

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

话虽如此,当我启动应用程序pserve development.ini ...数据库没有连接或加载。当我使用sqlite url 时,数据库连接。

我可能缺少什么?

development.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

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

postgres 服务器日志:

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

我必须更改postgres config file 吗? (stacks question 也提到了它)...我在pg_hba.conf 看到了这个:

# "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 服务器自动启动

我如何启动 Pyramid 应用程序:

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

【问题讨论】:

  • 能否请您编辑问题以包含“未加载”的相关错误消息并检查 PostgreSQL 日志文件。
  • @MikkoOhtamaa 我希望我收到not loading 提示...我收到No data received ERR_EMPTY_RESPONSE. Unable to load the webpage because the server sent no data.
  • 你需要得到一个 Python 回溯错误,而不是你的网络服务器所说的。它位于 Pyramid 应用程序的控制台或日志文件中。
  • 另外,不同的操作系统对不同的 PostgreSQL 版本的配置也不同,因此请包括有关此的信息。
  • 此外,如果 PSQL 上没有密码,则连接字符串应类似于 postgresql://localhost/notssdb

标签: python postgresql sqlalchemy pyramid


【解决方案1】:

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

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

这里的端口参数是pserve监听端口,改成8000什么的。

【讨论】:

  • 是的,端口更改允许postgres 与金字塔交互。我偶然发现了这一点,但是您的解释对于可能遇到相同问题的人来说更好。谢谢谢尔盖。
猜你喜欢
  • 1970-01-01
  • 2021-11-18
  • 2011-04-10
  • 2011-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-21
  • 1970-01-01
相关资源
最近更新 更多