【发布时间】:2018-02-28 22:16:14
【问题描述】:
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
我得到了一个不同的端口(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 -h 199.92.170.64 -d rtu_prod -Usv-read -p 5432 来启动它,但这要求输入我从未听说过的密码Password for user sv-read:
【问题讨论】:
-
psql -h /tmp?psql -h localhost? -
第一个返回
psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?有趣的是它的不同套接字。第二个返回:psql: FATAL: could not load pg_hba.conf然后我可能安装了两个版本的 posgresql... -
TBH 我不知道 PostgreSQL 是否可以在 Windows Linux 子系统上运行。我们目前没有 buildfarm 成员来测试它,因为没有人关心。这取决于它真正兼容的程度。为什么不直接使用本机 Windows PostgreSQL?
-
它在 WSL 中工作,我想在 WSL 中使用以学习如何在没有 GUI 的情况下使用。我用
psql -h 199.xx.xxx.64 -d rtk_prcd -U sv-read -p 5432连接到一个同事数据库并且我很好,所以我不知道发生了什么。 -
@CraigRinger 在命令中添加 '-h localhost' 使它对我有用。 'psql'、'createdb db_name' 等给了我错误。 'psql -h localhost'、'createdb db_name -h localhost' 都有效。
标签: postgresql windows-subsystem-for-linux