I have an aws ec2 instance that is running postgres on it. I have a file in the same instance that is a csv file so that I can populate the database. When I go into postgres to run the copy file, it is saying that the permission is denied. I am accessing the postgress shell with a superuser. I am not sure why I am getting a permission denied. Here is a screen shot of what I am running and error I am getting.
You don't say what OS user has launched psql, but presumably it's postgres.
It doesn't have the right to read any file inside /home/ec2-user because this directory has permissions drwx------, meaning that only ec2-user or root can look into it (the fact that the CSV file itself has world-wide read permissions is not sufficient, all directories in the hierarchy must have the x bit set to allow traversal).
The most common solutions:
1) chmod 755 /home/ec2-user so postgres can access it.
2) Launch psql under the ec2-user with an explicit -U option to specify a database user. This may also mean that a password is going to be asked, depending on Postgres authentication rules set in pg_hba.conf. You may also edit these rules if you're an admin and they don't match your needs.
3) Put the CSV data files in a dedicated directory that both ec2-user and postgres can read, so typically that would be outside of any /home directory.
I have tried
Setting the permission of .pgpass to 0600
Confirmed .pgpass is in my user's home directory (/home/brandon/.pgpass)
use -w in pg_dumpall command
Confirmed the data in .pgpass is correct
The script (https://wiki.postgresql.org/wiki/Automated_Backup_on_Linux) for automated backup works if I type the password again and again which is why i added -w to all the commands. It for some reason does not read the .pgpass file .
There are multiple error messages but they are generally this.
pg_dumpall: could not connect to database "template1": FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres"
pg_pass file :
localhost:5432:my_db:postgres:password
command line :
username#droplet:~/ProjectDir$ bash cronjob/db_backup/pg_backup.sh
Making backup directory in /home/backups/database/postgresql/2017-12-06/
Performing globals backup
--------------------------------------------
Globals backup
cronjob/db_backup/pg_backup.sh: line 80: /home/backups/database/postgresql/2017-12-06/globals.sql.gz.in_progress: Permission denied
pg_dumpall: could not connect to database "template1": fe_sendauth: no password supplied
[!!ERROR!!] Failed to produce globals backup
Performing schema-only backups
--------------------------------------------
psql: fe_sendauth: no password supplied
The following databases were matched for schema-only backup:
Performing full backups
--------------------------------------------
psql: fe_sendauth: no password supplied
All database backups complete!
You should supply the actual calls to pg_dump and pg_dumpall for a more detailed answer.
However, from your output I see that pg_dumpall (?) tries to connect to database template1, but in your .pgpass file the only database is my_db.
You'll have to add entries to .pgpass for all databases to which you are trying to connect.
localhost:5432:mydb1:postgres:password
localhost:5432:mydb2:postgres:password
localhost:5432:mydb3:postgres:password
Alternatively, you are also able to put an * as a placeholder for different database names.
localhost:5432:*:postgres:password
Make sure that all the fields in .pgpass are the right/matching ones. If any of them (host, port, etc.) don't match, the unclear, uninformative and arguably wrong fe_sendauth: no password supplied error message will be the same.
I'm trying to set up a Heroku environment for python development following instructions on https://github.com/heroku/python-getting-started. When I run createdb python_getting_started:
I'm first prompted to give in a password: I entered the password of the user "postgres" in Postgres
I get an error message:
createdb database creation failed: ERROR: permission denied to create database
Don't really how to solve this one. The user "postgres" is allowed to create a database. I checked with \du that it is a Superuser and it has Create DB rights. What's going on here? Which user is Windows using to try to create a Postgres DB?
Most PostgreSQL utilities by default use your current OS session login for database connections.
You need to either set environment variable PGUSER to postgres or use createdb -U postgres python_getting_started.
You can read more about createdb parameters here, tho admittedly it does not mention default values.
EDIT: It actually does mention that it uses libpq defaults, and those are:
user
PostgreSQL user name to connect as. Defaults to be the same as the operating system name of the user running the application.
I am pretty much confused about root user,super user,user and permissions! I am not able to create a database inside user "athleticu". Following are the commands I used:-
athleticu#ip-172-30-4-103:/home/ubuntu$ createdb -T template0 simple_db1
createdb: database creation failed: ERROR: permission denied to create database
athleticu#ip-172-30-4-103:/home/ubuntu$ sudo createdb -T template0 simple_db1
sudo: unable to resolve host ip-172-30-4-103
createdb: could not connect to database template1: FATAL: role "root" does not exist
Please somebody clarify my doubts and tell me what should I write!
Hey I have already solved this. What you have to do is to first login as postgres user as follows:
$ su postgres
$ psql
postgres=# alter user athleticu createdb;
ALTER ROLE
Hope it helps you :)
Type \du in psql and you will see a list of all the registered users and what type of privileges each one has.
In order to grant privileges to the user which is logged in (eg 'user1'), I had to sign out and log in using one of the superuser roles in that list (eg. 'user2'), using the following command:
psql -U 'user2' -h localhost 'database2'
where 'database2' is the name of the one that specific superuser 'user2' has privileges to.
Once you are logged in as a superuser, you can grant privileges to 'user1' by:
ALTER ROLE user1 WITH CREATEDB
or
ALTER ROLE user1 WITH SUPERUSER
Then sign in again as user1, who is now a superuser.
This blog was helpful as well as this link.
Currently, this worked for me:
sudo su postgres
psql
ALTER USER username WITH CREATEDB;
\q
exit
The root user is an account on the system independent from Postgres. There is only one root user.
A superuser is an account in Postgres with access to everything. There may be many superusers.
System accounts and Postgres accounts are different things, although unless you specify a Postgres username when you connect to the database (through utilities like psql, createdb, dropdb, or otherwise), it will use the current system user's name in hopes that there is a corresponding Postgres account with the same name. The root user does not, by default, have a corresponding account in Postgres.
When you install Postgres on *nix, it creates both a superuser named postgres and a system user named postgres.
Therefore, when you need to do something with Postgres as the built-in superuser, you have two options:
You may sudo su - postgres to become the postgres system user and execute your command (createdb, psql, etc). Because the system user has the same name as the database superuser, your command will connect as the appropriate account.
You may specify the username to execute as with the -U switch, eg psql -U postgres ....
Depending on your Postgres server's authentication settings, you may be required to enter a password with either or both connection methods.
What you can do when you have fresh installation of PostgreSQL is create your user with some rights (see createuser documentation):
my-user> sudo su - postgres -c "createuser <my-user> --createdb"
This will allow my-user to create DBs just like so:
my-user> createdb <my-db>
If you want the my-user to be able to do anything just use the --superuser flag instead:
my-user> sudo su - postgres -c "createuser <my-user> --superuser"
I got the same error and I found out that the reason was that I was trying to create a database outside of psql as a user which did not exist for postgresql. I found out about it and solved it by taking the following steps:
In my terminal I logged in as postgres user (the root user by default for postgresql) by typing sudo -u postgres psql
While inside the psql I typed \du to see all users and their privileges. I found out that I had only one user (the postgres one) and I had to create another superuser which had the same username as my Linux user (george)
I typed (still inside psql) CREATE USER george SUPERUSER; and this way I created a new super user called george.
I exited psql (by typing \q) and I was now able from outside psql, meaning from my terminal, to run created db <database name> with no issues at all.
Error ? You are trying to perform database actions( Creating Database, creating Roles) using a user that doesn't have the permission for those types of actions you are trying to perform.
solution ? Simply login to your database on the command line, i.e for PostgreSQL one will use "sudo -u postgres psql", then confirm that users specific assigned roles using the command "\du", most probably he/she doesn't have the necessary permissions to perform the actions you wanted. Then simply assign the roles you want the user to perform ,i.e create Database or simply make user "Superuser" by following along(https://chartio.com/resources/tutorials/how-to-change-a-user-to-superuser-in-postgresql/)
I installed openerp 7 on ubuntu and worked for a while.
When I restarted ubuntu, I opened openerp and tried to login but didn't find the databases I've created before and it took me to the (Database Management) page in order to create a new database as if it were my first time.
I tried to make a duplicate of an existing database as a workaround, but when I wrote the old database name, I got this message:
ProgrammingError: permission denied to copy database "test"
I tried to access postgres using pgadmin and I succeeded and could access all the databases from the pgadmin.
You need to give the access rights on particular database for particular openerp user.
First Create the OpenERP user that will own and run the application
sudo adduser --system --home=/opt/openerp --group openerp
Then Next,
First change to the postgres user so we have the necessary privileges to configure the database.
sudo su - postgres
Now create a new database user. This is so OpenERP has access rights to connect to PostgreSQL and to create and drop databases. Remember what your choice of password is here; you will need it later on:
createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt openerp
Enter password for new role: ********
Enter it again: ********
Finally exit from the postgres user account:
exit
Here is source link http://www.theopensourcerer.com/2012/12/how-to-install-openerp-7-0-on-ubuntu-12-04-lts/