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-#
내 파이썬 코드를 실행할 때 :
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 소켓"과 관련된 문제입니까? 내 로컬 호스트가 아닌 것은 무엇입니까?
내가 실행할 때 :
/mnt/c/WINDOWS/system32/virtualenv/dedupe/dedupe-examples/pgsql_big_dedupe_example$ service postgresql status
반환: 10/메인(포트 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)