POSTGRESQL cannot create a database. The following error occurs: createdb: cocould not connect.

Source: Internet
Author: User
Tags postgresql psql unix domain socket

Run the following command to create a database named mydb

The code is as follows:

Createdb mydb

The following error is returned: psql: FATAL: role "terry" does not exist. terry is the name of my machine and there is no role named terry in the postgresql database. Therefore, this error is reported, you only need to add the-U parameter to specify an existing role, so I changed the above command:

The code is as follows:

Createdb mydb-U postgres

Another error is returned: psql: FATAL: Peer authentication failed for user "s ",

The solution is as follows:

1. Run the following command to edit the pg_cmd.conf file.

The code is as follows:

Sudo gedit/etc/postgresql/9.1/main/pg_assist.conf

2. Set

The code is as follows:

# Database administrative login by Unix domain socket
Local all IPVs peer

Change

# Database administrative login by Unix domain socket
Local all IPVs trust

3. Save and execute the following command to reload the configuration file:

The code is as follows:

Sudo/etc/init. d/postgresql reload

Then run createdb mydb1-U postgres to create the mydb1 database.


You have not translated a foreign document. For more information, see.

I figured I 'd share getting setup on my Ubuntu machine.

Installing

Sudo apt-get install postgresql
Creating User

Createdb book
Createuser: cocould 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 shoshould work

Createdb book


Installing Extensions
There shoshould be more problems when trying to create the 5 extensions

Psql book-c "create extension tablefunc"
ERROR: cocould 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 shoshould be good to go!

Thanks to the post by Tanner Watson for the create extension command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.