在stackoverflow上似乎有很多类似的问题,但是它们似乎都没有帮助到我。我正在Windows Linux子系统上运行Ubuntu,并尝试安装和使用PostgreSQL。
我像这样安装:
sudo apt-get install postgresql postgresql-contrib postgresql-client
pgadmin3
它运行得很好:
在安装日志的底部附近,它说:
Creating new cluster 9.5/main ...
config /etc/postgresql/9.5/main
data /var/lib/postgresql/9.5/main
locale C
socket /var/run/postgresql
port 5433
update-alternatives: using /usr/share/postgresql/9.5/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
invoke-rc.d: could not determine current runlevel
Setting up postgresql (9.5+173) ...
Setting up postgresql-client (9.5+173) ...
Setting up postgresql-contrib-9.5 (9.5.8-0ubuntu0.16.04.1) ...
Setting up postgresql-contrib (9.5+173) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
端口号是5433。这也是postgresql.conf文件中列出的端口。
当我输入psql
时,我得到:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5433"?
当我执行以下命令时:
ps -df | grep postgres
spotter 12 2 0 18:55 tty1 00:00:00 /usr/lib/postgresql/9.5/bin/psql -h 199.92.170.64 -d rtu_prod -Usv-read -p 5432
spotter 1835 2 0 20:21 tty1 00:00:00 grep --color=auto -a postgres
spotter 6134 2 0 20:51 tty1 00:00:00 grep --color=auto -a postgres
spotter 9348 2 0 22:06 tty1 00:00:00 grep --color=auto postgres
我认为这可能意味着我安装了两个版本的PostgreSQL,但我不确定。
根据其他帖子的内容,我应该输入
/usr/lib/postgresql/9.5/bin/psql -h 199.92.170.64 -d rtu_prod -Usv-read -p 5432
来启动它,但这要求我输入一个我从未听说过的密码Password for user sv-read:
。
psql -h /tmp
?psql -h localhost
? - Craig Ringerpsql: 无法连接到服务器:没有这样的文件或目录 服务器是否在本地运行并接受 Unix 域套接字“/tmp/.s.PGSQL.5432”上的连接?
有趣的是它使用了不同的套接字。第二个返回的是:psql: 致命错误:无法加载 pg_hba.conf
那么我可能安装了两个版本的postgresql... - Stefano Potterpsql -h 199.xx.xxx.64 -d rtk_prcd -U sv-read -p 5432
连接到同事的数据库,并成功进入,所以我不知道出了什么问题。 - Stefano Potter