Windows Linux子系统和postgresql连接失败
在stackoverflow上似乎有很多这样的问题,但似乎没有一个对我有帮助。我在windows linux子系统上运行Ubuntu,并尝试安装和使用postgresql 我是这样安装的:Windows Linux子系统和postgresql连接失败,postgresql,windows-subsystem-for-linux,Postgresql,Windows Subsystem For Linux,在stackoverflow上似乎有很多这样的问题,但似乎没有一个对我有帮助。我在windows linux子系统上运行Ubuntu,并尝试安装和使用postgresql 我是这样安装的: sudo apt-get install postgresql postgresql-contrib postgresql-client pgadmin3 效果很好: 靠近底部的安装日志显示: Creating new cluster 9.5/main ... config /etc/postgresq
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
但我得到了一个不同的端口(5432),返回的是:
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-h199.92.170.64-d rtu_prod-Usv read-p5432
来启动它,但这要求输入一个我从未听说过的密码用户sv read的密码:
postgresql与WSL配合得很好。要完全运行它,请执行以下步骤:
安装步骤:
sudo apt更新
sudo-apt-install-postgresql-postgresql-contrib
sudo服务postgresql启动
sudo-i-u postgres
psql
使用密码“”创建用户代码>
与所有者一起创建数据库代码>
\password postgres
psql-h/tmp
psql-h localhost
?返回的第一个文件psql:无法连接到服务器:没有这样的文件或目录是在本地运行并接受Unix域套接字上的连接的服务器“/tmp/.s.PGSQL.5432”?
它是另一个套接字。第二个返回:psql:FATAL:无法加载pg_hba.conf
我可能安装了两个版本的posgresql…TBH我不知道PostgreSQL是否在Windows Linux子系统上工作。我们目前没有buildfarm成员来测试它,因为没有人关心它。这取决于它真正的兼容性。为什么不直接使用本机Windows PostgreSQL呢?它在WSL中工作,我想在WSL中使用它来学习如何在没有GUI的情况下使用。我用psql-h199.xx.xxx.64-d rtk_prcd-U sv read-p5432
连接到一个同事的数据库,结果很好,所以我不知道发生了什么。@CraigRinger在命令中添加“-h localhost”使它对我起作用psql、createdb db_name等给了我错误信息psql-h localhost、“createdb db_name-h localhost”都起作用。