2015-10-15 80 views
2

金字塔金字塔PostgreSQL的連接問題

從SQLITE3移動到PostgreSQL(PSQL(PostgreSQL的)9.4.5),我一直在使用sqlite3訪問sqlalchemy數據庫。我開發了一個pyramid Web框架,並且sqlite3一直在工作。但是,我想從使用sqlite3開始,而不是使用postgresql作爲db。我對此很陌生,並試圖弄清楚我是否缺少一個步驟。

我在下載psycopg2this tutorial跟隨(添加它的setup.py)從改變development.ini文件:
sqlalchemy.url = sqlite:////Users/ack/code/venv/NotssDB/notssdb/notssdb
到:
sqlalchemy.url = postgresql://ack:[email protected]:5432/notssdb
我使用的Mac OSX經由this site安裝postgres的。

這樣說,當我啓動應用程序pserve development.ini ...數據庫沒有連接或加載。當我使用sqlite網址時,數據庫連接。

我可能會丟失什麼?

development.ini 在金字塔:

sqlalchemy.url = postgresql://ack:[email protected]: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? (A 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服務器自動啓動

如何啓動金字塔應用程序:

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

可否請編輯該問題以包含「未加載」的相關錯誤消息,並檢查PostgreSQL日誌文件。 –

+0

@MikkoOhtamaa我希望我有一個'不加載'提示...我收到'沒有收到數據ERR_EMPTY_RESPONSE。無法加載網頁,因爲服務器未發送任何數據。「# – thesayhey

+0

您需要獲取Python追溯錯誤,而不是您的Web服務器所說的內容。它位於金字塔應用程序的控制檯或日誌文件中。 –

回答

2

不知道這是唯一的問題,但它看起來你有端口衝突。您嘗試在同一端口上啓動pyramid應用程序(通過pserve)postgresql默認偵聽(5432)。

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

此處的端口參數是用於pserve監聽端口,將其更改爲8000或其他。

+0

是的端口改變允許'postgres'與金字塔交互。我認爲這是出於偶然,但你的解釋對那些可能會遇到同樣問題的人來說更好。謝謝謝爾蓋。 – thesayhey