最新下载
热门教程
- 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
相关文章
- 《无限暖暖》天星之羽获得位置介绍 12-20
- 《流放之路2》重铸台解锁方法介绍 12-20
- 《无限暖暖》瞄准那个亮亮的成就怎么做 12-20
- 《无限暖暖》魔气怪终结者完成方法 12-20
- 《无限暖暖》曙光毛团获得位置介绍 12-20
- 《无限暖暖》日光果获得位置介绍 12-20