Ubuntu Bash コマンドで重複排除ライブラリとこの例を実行しようとしています。
https://github.com/dedupeio/dedupe-examples/tree/master/pgsql_big_dedupe_example
基本的に、データベース名をリストするとわかるように、campfin というデータベースを作成しました。
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------------+----------+---------+---------+-----------------------
campfin | simon | UTF8 | C.UTF-8 | C.UTF-8 |
dbname | owning_user | UTF8 | C.UTF-8 | C.UTF-8 |
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
postgres=# \c campfin
You are now connected to database "campfin" as user "postgres".
campfin=# sudo netstat -plunt |grep postmaster
campfin-# \conninfo
You are connected to database "campfin" as user "postgres" via socket in "/var/run/postgresql" at port "5433".
campfin-#
Python コードを実行すると:
python3 pgsql_big_dedupe_example_init_db.py
または
sudo python3 pgsql_big_dedupe_example_init_db.py
これはデータベースに接続するモードの部分です。
conn = psycopg2.connect(database=db_conf['campfin'],
user=db_conf['111'],
password=db_conf['111'],
host=db_conf['localhost'],
port=db_conf['5433'])
データベース campfin が存在しないという結果が返されます:
Traceback (most recent call last):
File "pgsql_big_dedupe_example_init_db.py", line 75, in <module>
conn = psycopg2.connect(database=db_conf['campfin'],
KeyError: 'campfin'
ここで何が間違っているのでしょうか? 問題は「/var/run/postgresql」の「via socket」に関連していますか? これは私のローカルホストではありませんか?
実行すると:
/mnt/c/WINDOWS/system32/virtualenv/dedupe/dedupe-examples/pgsql_big_dedupe_example$ service postgresql status
戻り値: 10/main (ポート 5433): オンライン
答え1
db_conf['NAME']
に変更されるものではありませんdb_conf['campfin']
。鍵それNAME
は価値それはそうなるでしょうcampfin
!
コマンドラインで、以下を実行します。
export DATABASE_URL=postgres://111:111@localhost/campfin
次に、python3 pgsql_big_dedupe_example_init_db.py
元のコードで実行します...
con = psycopg2.connect(database=db_conf['NAME'],
user=db_conf['USER'],
password=db_conf['PASSWORD'],
host=db_conf['HOST'],
cursor_factory=psycopg2.extras.RealDictCursor)