我是postgres的新手。

我安装了postgres。我在玩psql命令,我不小心掉了postgres数据库。我不知道里面有什么。

我目前正在制作一个教程:http://www.rosslaird.com/blog/building-a-project-with-mezzanine/

我被困在sudo -u postgres psql postgres

错误信息:psql: FATAL: role "postgres"不存在

$ which PSQL

/Applications/Postgres.app/Contents/MacOS/bin/psql

这是psql -l输出的内容

                                List of databases
    Name    |   Owner    | Encoding | Collate | Ctype |     Access privileges     
------------+------------+----------+---------+-------+---------------------------
 user       | user       | UTF8     | en_US   | en_US | 
 template0  | user       | UTF8     | en_US   | en_US | =c/user                  +
            |            |          |         |       | user      =CTc/user      
 template1  | user       | UTF8     | en_US   | en_US | =c/user                  +
            |            |          |         |       | user      =CTc/user      
(3 rows)

那么我应该采取哪些步骤呢?删除一切相关的psql和重新安装一切?

谢谢你们的帮助!


当前回答

如果你正在使用docker,确保你没有使用POSTGRES_USER=something_else,因为这个变量被标准映像用来知道PostgreSQL管理用户的名称(默认为postgres)。

在我的例子中,我使用这个变量的目的是将另一个用户设置到我的特定数据库,但它最终当然改变了主PostgreSQL用户。

其他回答

MAC:

安装自酿酒 酿造安装postgres initdb /usr/local/var/postgres /usr/local/ cellar /postgresql/<version>/bin/createuser -s postgres或/usr/local/opt/ postgress /bin/createuser -s postgres只使用最新版本。 手动启动postgres服务器:pg_ctl -D /usr/local/var/postgres start


在启动时启动服务器

mkdir -p ~/库/启动代理 Ln -sfv /usr/local/opt/postgresql/*。plist ~ /图书馆/ LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mx .postgresql.plist


现在,它已经设置好了,使用psql -U postgres -h localhost或使用PgAdmin进行GUI登录。

默认情况下,postgres用户没有任何登录密码。

查看此站点以获取更多类似文章:https://medium.com/@Nithanaroy/ installing-postgre-on -mac-18f017c5d3f7

在Mac上,执行

createuser -s postgres

在一个终端工作。

createuser postgres --interactive

或者创建一个超级用户postgresl

createuser postgres -s

如果你在2023年,想知道最新的Postgres在最新的macOS (macOS Monterey)上有什么用

遵循这个:

brew install postgresql
createuser -s postgres
brew services restart postgresql

对我来说,这个代码是有效的:

/Applications/Postgres.app/Contents/Versions/9.4/bin/createuser -s postgres

它来自这里: http://talk.growstuff.org/t/fatal-role-postgres-does-not-exist/216/4