postgres permission issue when logged in as a user - postgresql

I know this is a db question and I posted the question there and didn't get any response. If anyone can help, it would be great. I even followed the instructions on here: http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/ but no luck.
I'm logged in as a user in postgres with PgAdmin tool in Linux connecting remotely but I don't think the user has enough rights. I'm a MySQL experienced user but not so much in PostGres. When I select a table when logged in as the user I get
An error has occurred:
ERROR: permission denied for relation acs_activities
how do I add my user "gainpm" to have access to all tables in "projop" database?

I figured it out. First I had to login as superuser
sudo -u postgres psql
then issue
ALTER USER myuser WITH SUPERUSER;

Related

Postgres 13: cannot psql from CMD (incorrect password but its correct?)

Image of my info and the error itself
Yes I can access it by Shell and pgAdmin but I cannot with direct psql command...
Does anyone have any insight?
The thing that confused me was from the CMD I managed to connect as AN USER NAMED "POSTGRES" and connected to a database named "POSTGRES", for a while, I thought users and databases were one thing. Later, I thought that "POSTGRES" is like a master user and I can create many many databases with it then I found out I could create users ...
postgres=#CREATE USER me WITH PASSWORD '0000';
Add to that confusion, I managed to connect as an different user but it was still saying "postgres=#_" not a "differentuser=#" then I figured out that "postgres=#" is the database named "POSTGRES". There weren't any noob friendly tutorials on Youtube that I was able to find... I guess the pgAdmin 4 helped because I wasn't familiar yet with \du+ \l commands. I hope someone finds this useful.

How to create the first DB in Postgres

I have just installed Postgres 12 on a Mac. As you may soon appreciate I am totally new to it.
During the installation process I was asked to provide a "password". I do not remember specifically, but I think it was for the some sort of admin role.
Now I want to create my first database. Reading the documentation I insert the command
createdb myfistdb
the system asks for a password. I give the one I set during the installation processes but I got the following error
createdb: error: could not connect to database template1: FATAL: password authentication failed for user "myusername"
where myusername is the user I am logged in.
The same happens if I give the system password of myusername.
I understand that my question is pretty basic, but I have been struggling quite some time without any success, so any help will be appreciated.
The database uset name used by createdb defaults to the operating system user name, so you'll have to specify the administrative superuser explicitly:
createdb -U postgres myfistdb

createdb: database creation failed: ERROR: permission denied to create database

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/)

psql: permission denied for database "dbname" ("User does not have CONNECT privilege.") / "unrecognized role option 'connect'"

when I try to login to my database with psql, doing this:
psql dbname --username=qgis --password
>>(prompts for password, entered password)
psql: FATAL: permission denied for database "gisdatabase"
DETAIL: User does not have CONNECT privilege.
I've searched around on Google for information on this simple issue but haven't found anyone directly talking about this.
I've tried doing this:
psql dbname
>>ALTER ROLE qgis WITH CONNECT;
But got this error:
ERROR: unrecognized role option "connect"
So once again, here I am, asking yet another question on stackoverflow. Thanks for your time folks
You need to grant a privilege. Try this:
psql dbname
>> GRANT CONNECT ON DATABASE dbname TO qgis;
I assume you will also need further privileges. PostgreSQL has one of the best documentation pages of all the DBMSs: http://www.postgresql.org/docs/9.0/static/sql-grant.html (You can choose the postgres version you're using at the top of the page).

Postgres user create database

I am unable to create databases using my postgres client with the user I log in as.
I am having trouble figuring out how increase the privileges of my user. I have access to the linux server running postgres and am able to use psql to log on as my user and as the postgres user.
Can someone tell me what commands I should run to allow my user to create databases on my server through the postgres GUI running on a remote host?
Many thanks,
I donĀ“t know of a postgres GUI, but here's how to do it in the psql-console (logged in as the superuser):
=> ALTER USER your_username CREATEDB;
See http://www.postgresql.org/docs/current/interactive/sql-alteruser.html for more info.