博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
psql: FATAL: role “postgres” does not exist
阅读量:6715 次
发布时间:2019-06-25

本文共 2484 字,大约阅读时间需要 8 分钟。

I'm a postgres novice.

I installed the postgres.app for mac. I was playing around with the psql commands and I accidentally dropped the postgres database. I don't know what was in it.

I'm currently working on a tutorial: 

And I'm stuck at sudo -u postgres psql postgres

ERROR MESSAGE: psql: FATAL: role "postgres" does not exist

$ which psql

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

This is what prints out of 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)

So what are the steps I should take? Delete an everything related to psql and reinstall everything?

Thanks for the help guys!

 linux配置
 
242accepted

Note that the error message does NOT talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.

But the first step is to check the missing role: What is the output within psql of the command \du ? On my Ubuntu system the relevant line looks like this:

List of roles Role name |            Attributes             | Member of -----------+-----------------------------------+----------- postgres  | Superuser, Create role, Create DB | {}

If there is not at least one role with superuser, then you have a problem :-)

If there is one, you can use that to login. And looking at the output of your \l command: The permissions for user on the template0 and template1 databases are the same as on my Ubuntu system for the superuser postgres. So I think your setup simple uses user as the superuser. So you could try this command to login:

sudo -u user psql user

If user is really the DB superuser you can create another DB superuser and a private, empty database for him:

CREATE USER postgres SUPERUSER;CREATE DATABASE postgres WITH OWNER postgres;

But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.

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

 

 

转载地址:http://jiilo.baihongyu.com/

你可能感兴趣的文章
SQL-GROUP BY第四课
查看>>
Kubernetes 1.12全新发布!新功能亮点解析
查看>>
大型商城购物车原理
查看>>
CentOS下yum安装PHP,配置php-fpm服务
查看>>
搭建基于SSM的分布式电子商城的框架开源方便大家二次开发(已解决跨域问题)...
查看>>
感恩节那天,亚洲诚信收到了一封来自客户的致谢信……
查看>>
王坚:什么是真正的创新?| 干货
查看>>
SQL Server on Linux入门教程
查看>>
可直接嵌入业务系统为终端客户提供分析服务的阿里云分析型数据库
查看>>
DAO开发实战业务分析
查看>>
1.8 httpd的用户认证
查看>>
Mybatis2
查看>>
追加字节能优化性能
查看>>
哈希表原理
查看>>
学习运维需求分析、域名申请、域名解析、域名备案
查看>>
Java 定时任务调度工具 Quartz(Part 1)
查看>>
一个JSON字符串和文件处理的命令行神器jq,windows和linux都可用
查看>>
技术沙龙|利用IPFS,去中心化存储如何让钱包更安全?(南京)
查看>>
数据库:数据库设计三大范式
查看>>
第17次课
查看>>