3

I have installed postgresql on ubuntu using:

$ sudo apt install postgresql

Now, I have a series of sql queries I would like to fire to create schemas and users and tables etc. I have put those queries in a .sql file as below:

$ sudo nano postgressetup.sql
CREATE SCHEMA schma;
CREATE USER a2i WITH PASSWORD 'password';
GRANT CONNECT ON DATABASE postgres TO schma;

This file has all the queries. I tried something like:

$ psql -U postgres -d postgres -a -f postgressetup.sql

and received error:

psql: FATAL:  Peer authentication failed for user "postgres"

I want to know the way I can execute this .sql file. Note: I've just installed postgres and no further operation is done on it. Any help is appreciated.

1
  • See here Commented Nov 29, 2018 at 13:55

1 Answer 1

2

You can use the following command explicitly providing db context user

sudo -u postgres psql -U postgres -d postgres -a -f postgressetup.sql

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.