如何在 Windows 上启动 PostgreSQL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36629963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I start PostgreSQL on Windows?
提问by Sean
I have installed Postgresql on my Windows 10 PC. I have used the pgAdmin II tool to create a database called company, and now I want to start the database server running. I cannot figure out how to do this. I have run the start command on the postgres command line, and nothing seems to happen.
我已经在我的 Windows 10 PC 上安装了 Postgresql。我已经使用 pgAdmin II 工具创建了一个名为 company 的数据库,现在我想启动数据库服务器运行。我无法弄清楚如何做到这一点。我已经在 postgres 命令行上运行了 start 命令,但似乎没有任何反应。
What I doing is:
我所做的是:
postgres=# pg_ctl start
postgres=# pg_ctl status
postgres=# pg_ctl restart
postgres=# pg_ctl start company
postgres=# pg_ctl status
.....-> I am seeing nothing returned.
.....-> 我没有看到任何回报。
回答by a_horse_with_no_name
pg_ctl
is a command line (Windows) program nota SQL statement. You need to do that from a cmd.exe
. Or use net start postgresql-9.5
pg_ctl
是命令行 (Windows) 程序而不是SQL 语句。您需要从cmd.exe
. 或使用net start postgresql-9.5
If you have installed Postgres through the installer, you should start the Windows serviceinstead of running pg_ctl
manually, e.g. using:
如果你已经通过安装程序安装了 Postgres,你应该启动 Windows服务而不是pg_ctl
手动运行,例如使用:
net start postgresql-9.5
Note that the name of the service might be different in your installation. Another option is to start the service through the Windows control panel
请注意,服务的名称在您的安装中可能会有所不同。另一种选择是通过 Windows 控制面板启动服务
I have used the pgAdmin II tool to create a database called company
我使用 pgAdmin II 工具创建了一个名为 company 的数据库
Which means that Postgres is already running, so I don't understand why you think you need to do that again. Especially because the installer typically sets the service to start automatically when Windows is started.
这意味着 Postgres 已经在运行,所以我不明白你为什么认为你需要再次这样做。特别是因为安装程序通常将服务设置为在 Windows 启动时自动启动。
The reason you are not seeing any result is that psql
requires every SQLcommand to be terminated with ;
in your case it's simply waiting for you to finish the statement.
您没有看到任何结果的原因是psql
需要在您的情况下终止每个SQL命令,;
它只是在等待您完成语句。
See here for more details: In psql, why do some commands have no effect?
更多细节请看这里:在psql中,为什么有些命令没有效果?
回答by Santosh Patel
Go inside bin folder in C drive where Postgres is installed. run following command in git bash or Command prompt:
进入安装 Postgres 的 C 驱动器中的 bin 文件夹。在 git bash 或命令提示符中运行以下命令:
pg_ctl.exe restart -D "<path upto data>"
Ex:
前任:
pg_ctl.exe restart -D "C:\Program Files\PostgreSQL.6\data"
Another way: type "services.msc" in run popup(windows + R). This will show all services running Select Postgres service from list and click on start/stop/restart.
另一种方法:在运行弹出窗口(windows + R)中输入“services.msc”。这将显示所有运行的服务从列表中选择 Postgres 服务并单击启动/停止/重启。
Thanks
谢谢
回答by ALWAN
After a lot of search and tests i found the solution : if you are in windows :
经过大量搜索和测试,我找到了解决方案:如果您在 Windows 中:
1 - first you must found the PG databases directory execute the command as sql command in pgAdmin query tools
1 - 首先你必须找到PG数据库目录在pgAdmin查询工具中将命令作为sql命令执行
$ show data_directory;
result :
------------------------ - D:/PG_DATA/data - ------------------------
结果 :
------------------------ - D:/PG_DATA/data - ------------------------
2 - go to the bin directory of postgres in my case it's located "c:/programms/postgresSql/bin"
2 - 在我的情况下,转到 postgres 的 bin 目录,它位于“c:/programms/postgresSql/bin”
and open a command prompt (CMD) and execute this command :
并打开命令提示符(CMD)并执行以下命令:
pg_ctl -D "D:\PSG_SQL\data" restart
This should do it.
这应该这样做。
回答by Matthew Lock
回答by Nandan Chaturvedi
If you are getting an error "psql.exe' is not recognized as an internal or external command,... "
如果您收到错误“psql.exe' 未被识别为内部或外部命令,...”
There can be : Causes
可能有:原因
- System is unable to find the psql.exe tool, because the path to this tool is not specified in the system environment variable PATH
- 系统找不到psql.exe工具,因为系统环境变量PATH中没有指定这个工具的路径
or - PostgreSQL Database client not installed on your PC
或 - 您的 PC 上未安装 PostgreSQL 数据库客户端
Since you have already installed PostgreSQL the latter can not be the issue(assuming everything is installed as expected)
由于您已经安装了 PostgreSQL,因此后者不是问题(假设一切都按预期安装)
In order to fix the first one "please specify the full path to the bin directoryin the PostgreSQL installation folder, where this tool resides."
为了修复第一个“请指定该工具所在的 PostgreSQL 安装文件夹中bin 目录的完整路径。”
For example
例如
Path: "C:\Program Files\PostgreSQL\10\bin"
路径:“C:\Program Files\PostgreSQL\10\bin”
回答by Tomasz Plonka
I found using
我发现使用
net start postgres_service_name
net start postgres_service_name
the only reliable way to operate Postgres on Windows
在 Windows 上运行 Postgres 的唯一可靠方法
回答by Kathir M
Remove Postmaster file in "C:\Program Files\PostgreSQL\9.6\data"
删除“C:\Program Files\PostgreSQL\9.6\data”中的 Postmaster 文件
and restart the PostgreSQL services
并重启 PostgreSQL 服务
回答by Anupam Maurya
first find your binaries file where it is saved. get the path in terminal mine is
首先找到保存它的二进制文件。获取终端矿的路径是
C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin
C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin
then find your local user data path, it is in mostly
然后找到您的本地用户数据路径,它主要在
C:\usr\local\pgsql\data
now all we have to hit following command in the binary terminal path:
现在我们必须在二进制终端路径中点击以下命令:
C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin>pg_ctl -D "C:\usr\local\pgsql\data" start
C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin>pg_ctl -D "C:\usr\local\pgsql\data" start
all done!
全部完成!
autovaccum launcher started! cheers!
autovaccum 启动器启动了!干杯!