最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
POSTGRESQL 无法创建数据库 出现类似createdb: could not connect
时间:2022-06-29 10:24:04 编辑:袖梨 来源:一聚教程网
运行下面的命令创建名为mydb的数据库
代码如下 | 复制代码 |
createdb mydb |
得到一个错误:psql: FATAL: role "terry" does not exist, terry是我的机器名, 在postgresql数据库中没有名为terry的role, 所以会报出这个错误, 只要加上-U参数来指定一个存在的role就可以了,所以我将上面的命令改为:
代码如下 | 复制代码 |
createdb mydb -U postgres |
又得到一个错误:psql: FATAL: Peer authentication failed for user "postgres",
解决办法如下:
1. 运行下面的命令编辑pg_hba.conf文件
代码如下 | 复制代码 |
sudo gedit /etc/postgresql/9.1/main/pg_hba.conf |
2. 将
代码如下 | 复制代码 |
# Database administrative login by Unix domain socket 改为 # Database administrative login by Unix domain socket |
3. 保存后执行下面的命令重新加载配置文件:
代码如下 | 复制代码 |
sudo /etc/init.d/postgresql reload |
再执行 createdb mydb1 -U postgres , 已经成功的创建了mydb1数据库.
看一老外的文件没译,各位有需要可参考。
I figured I’d share getting setup on my Ubuntu machine.
Installing
sudo apt-get install postgresql
Creating User
createdb book
createuser: could not connect to database postgres: FATAL: role "myusername" does not exist
The bit above can be resolved with the following (replacing myusername for yours)
sudo -u postgres createuser myusername
Shall the new role be a superuser? (y/n) y
Then this should work
createdb book
Installing Extensions
There should be more problems when trying to create the 5 extensions
psql book -c "CREATE EXTENSION tablefunc"
ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/tablefunc.control": No such file or directory
You can fix it by just downloading a package.
sudo apt-get install postgresql-contrib
Downloading the postgresql-contrib packages will give the ability to use the following five commands:
psql book -c "CREATE EXTENSION tablefunc"
psql book -c "CREATE EXTENSION fuzzystrmatch"
psql book -c "CREATE EXTENSION pg_trgm"
psql book -c "CREATE EXTENSION cube"
psql book -c "CREATE EXTENSION dict_xsyn"
And now you should be good to go!
Thanks to the post by Tanner Watson for the CREATE EXTENSION command
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21