如何为 PostgreSQL 设置 localhost 服务器和数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48435976/
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 to set up localhost server and database for PostgreSQL?
提问by MikeLiu
I am new to PostgreSQL, and I want to use it on my personal laptop for personal projects. I use SQL Server and SQL Server Management Studio at work, coding-wise I'm ok but I need some help with setting up the localhost on my laptop.
我是 PostgreSQL 的新手,我想在我的个人笔记本电脑上使用它来进行个人项目。我在工作中使用 SQL Server 和 SQL Server Management Studio,在编码方面我没问题,但我需要一些帮助来在我的笔记本电脑上设置本地主机。
So I downloaded PostgreSQL and installed it along with pgAdmin that came with the package.
因此,我下载了 PostgreSQL 并将其与软件包附带的 pgAdmin 一起安装。
During installation, it asked me to create a PostgreSQL superuser password, which I did.
在安装过程中,它要求我创建一个 PostgreSQL 超级用户密码,我做到了。
Then I tried creating a new server using pgAdmin as follows:
然后我尝试使用 pgAdmin 创建一个新服务器,如下所示:
General Tab:
常规选项卡:
Name: localhost
Server Group: Servers
Connect Now?: check
名称:localhost
服务器组:Servers
Connect Now?:检查
Connection Tab:
连接选项卡:
Host name/address: localhost Port: 5432
Maintenance database: postgres
Username: postgres
Password: [blank]
主机名/地址:本地主机端口:5432
维护数据库:postgres
用户名:postgres
密码:[空白]
But when I click save I'm getting an error message:
但是当我点击保存时,我收到一条错误消息:
Unable to connect to server: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost"(::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost"(127.0.0.1) and accepting TCP/IP connections on port 5432?
无法连接到服务器:无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(127.0.0.1) 上运行并接受端口 5432 上的 TCP/IP 连接?
Also tried replacing the password field with the Superuser password, getting the same error message.
还尝试用超级用户密码替换密码字段,得到相同的错误消息。
Would greatly appreciate it if anyone offers any insights into this problem, I might just be a noob when it comes to server setups...
如果有人对这个问题有任何见解,我将不胜感激,在服务器设置方面,我可能只是个菜鸟......
Thanks, Mike
谢谢,迈克
Update: I believe there's a service I need to start as suggested by @Scott Moniz. I went into services.msc, tried to start the service postgresql-x64-10 - PostgreSQL Servier 10, and I got this error message:
更新:我相信我需要按照@Scott Moniz 的建议启动一项服务。我进入 services.msc,尝试启动服务postgresql-x64-10 - PostgreSQL Servier 10,我收到以下错误消息:
"The postgresql-x64-10 - PostgreSQL Server 10 service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs".
“本地计算机上的 postgresql-x64-10 - PostgreSQL Server 10 服务启动然后停止。如果其他服务或程序未使用某些服务,它们会自动停止”。
I then tried editing the property of the service, by changing the Log on asoption to Local System Accountand tried starting the service again, still got the same error message.
然后我尝试编辑服务的属性,通过将登录为选项更改为本地系统帐户并尝试再次启动该服务,但仍然收到相同的错误消息。
I'm using Windows 10 Home edition, it this helps to resolve the issues in anyway
我正在使用 Windows 10 家庭版,这有助于解决问题
Thanks, Mike
谢谢,迈克
回答by Scott Moniz
Are you sure the database service is running and listening? CLick Start>Run> type services.msc
您确定数据库服务正在运行和监听吗?单击开始>运行>键入services.msc
Look for a postgresql service - if it does not say started right click it and click Start.
查找 postgresql 服务 - 如果它没有显示已启动,请右键单击它并单击启动。
Alternatively you can restart your computer and the service should start if it is set to 'Automatic'
或者,您可以重新启动计算机,如果设置为“自动”,该服务应该会启动