我正在尝试在linux机器上的PostgreSQL上创建db . 我使用以下命令来创建数据库 .
createdb mydbname;
这会引发以下错误 .
createdb:无法连接到数据库postgres:FATAL:数据库“postgres”不存在
我是PostgreSQL的新手 . 你能指导我完成这个错误吗?我只想在psql上创建一个DB .
看起来你放弃了 postgres 数据库 . 它是许多管理操作的默认设置,因此您可能需要重新创建它:
postgres
createdb --maintenance-db=template1 -T template0 postgres;
正在做的是连接到内置数据库 template1 ,以便通过制作 template0 的副本来创建db postgres .
template1
template0
一旦完成,你的命令:
会正常工作 .
su - postgres 将用户更改为postgrespsql - 运行psql终端postgres# create database somedatabase 创建数据库;postgres#\c somedatabase connecto to databasesomedatabase# 您作为postgres用户连接到该数据库
su - postgres
psql
postgres# create database somedatabase
postgres#\c somedatabase
somedatabase#
su - postgres change user to postgres createdb createdb somedatabase psql somedatabase
第一行更改为postgres系统用户 . 第二行为postgres管理员用户创建一个数据库 . 第三行创建您尝试制作的数据库 . 第四行作为postgres用户连接到它 .
3 回答
看起来你放弃了
postgres
数据库 . 它是许多管理操作的默认设置,因此您可能需要重新创建它:正在做的是连接到内置数据库
template1
,以便通过制作template0
的副本来创建dbpostgres
.一旦完成,你的命令:
会正常工作 .
su - postgres
将用户更改为postgrespsql
- 运行psql终端postgres# create database somedatabase
创建数据库;postgres#\c somedatabase
connecto to databasesomedatabase#
您作为postgres用户连接到该数据库第一行更改为postgres系统用户 . 第二行为postgres管理员用户创建一个数据库 . 第三行创建您尝试制作的数据库 . 第四行作为postgres用户连接到它 .