postgresql 如何在 Ubuntu 上使用 pgAdmin 将 Postgres 连接到 localhost 服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24917832/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:45:36  来源:igfitidea点击:

How connect Postgres to localhost server using pgAdmin on Ubuntu?

postgresqldatabase-connectionpgadmin

提问by TuGordoBello

I installed Postgres with this command

我用这个命令安装了 Postgres

sudo apt-get install postgresql postgresql-client postgresql-contrib libpq-dev

Using psql --versionon terminal I get psql (PostgreSQL) 9.3.4

psql --version在终端上使用我得到psql (PostgreSQL) 9.3.4

then I installed pgadminwith

然后我安装pgadmin

sudo apt-get install pgadmin3

Later I opened the UI and create the server with this information

后来我打开了 UI 并用这些信息创建了服务器

enter image description here

在此处输入图片说明

but this error appear

但是出现这个错误

enter image description here

在此处输入图片说明

how can I fix it?

我该如何解决?

采纳答案by Eric Workman

You haven't created a user db. If its just a fresh install, the default user is postgresand the password should be blank. After you access it, you can create the users you need.

您尚未创建用户db。如果只是全新安装,则默认用户是postgres,密码应为空。访问它后,您可以创建所需的用户。

回答by WiredIn

Modify password for role postgres:

修改 postgres 角色的密码:

sudo -u postgres psql postgres

alter user postgres with password 'postgres';

Now connect to pgadmin using username postgres and password postgres

现在使用用户名 postgres 和密码 postgres 连接到 pgadmin

Now you can create roles & databases using pgAdmin

现在您可以使用 pgAdmin 创建角色和数据库

How to change PostgreSQL user password?

如何更改 PostgreSQL 用户密码?

回答by Artem Solovev

It helps me:

它帮助到我:



1. Open the file打开文件pg_hba.confpg_hba.conf

sudo nano /etc/postgresql/9.x/main/pg_hba.conf

须藤纳米 /etc/postgresql/9.x/main/pg_hba.conf

and change this line:

并更改此行:

Database administrative login by Unix domain socket
local   all             postgres                                md5

to

Database administrative login by Unix domain socket
local   all             postgres                                trust
  1. Restart the server

    sudo service postgresql restart

  2. Login into psqland set password

    psql -U postgres

  1. 重启服务器

    须藤服务 postgresql 重启

  2. 登录psql设置密码

    psql -U postgres

ALTER USER postgres with password 'new password';

ALTER USER postgres with password 'new password';

  1. Again open the filepg_hba.confand change this line:
  1. 再次打开文件pg_hba.conf并更改这一行:
Database administrative login by Unix domain socket
    local   all             postgres                                trust

to

    Database administrative login by Unix domain socket
    local   all             postgres                                md5
  1. Restart the server

    sudo service postgresql restart

  1. 重启服务器

    须藤服务 postgresql 重启



有用。

enter image description here

在此处输入图片说明



有用的链接


1:PostgreSQLPostgreSQL(来自 ubuntu.com)

回答by Str.

Create a user first. You must do this as user postgres. Because the postgres system account has no password assigned, you can either set a password first, or you go like this:

首先创建一个用户。您必须以 postgres 用户身份执行此操作。因为 postgres 系统帐户没有分配密码,你可以先设置密码,或者像这样:

sudo /bin/bash
# you should be root now  
su postgres
# you are postgres now
createuser --interactive

and the programm will prompt you.

程序会提示你。

回答by Pubudu

First you should change the password using terminal. (username is postgres)

首先,您应该使用终端更改密码。(用户名是 postgres)

postgres=# \password postgres

postgres=# \password postgres

Then you will be prompted to enter the password and confirm it.

然后系统会提示您输入密码并确认。

Now you will be able to connect using pgadmin with the new password.

现在您将能够使用 pgadmin 使用新密码进行连接。

回答by Elise Chant

if you open the psqlconsole in a terminal window, by typing

如果您psql在终端窗口中打开控制台,请键入

$ psql

$ psql

you're super user username will be shown before the =#, for example:

您是超级用户的用户名将显示在 之前=#,例如:

elisechant=#$

elisechant=#$

That will be the user name you should use for localhost.

这将是您应该用于 localhost 的用户名。