我正在尝试在 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”中的“通过套接字”有关?这不是我的本地主机?
当我跑步时:
/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)