postgres: error: db doesnt exist ( psql create user case senstivity issue) - postgresql

I have this database triviaDB that i am connecting to from a flask-sqlalchemy 'postgresql://devuser:devpass#localhost:5432/triviaDB'however it's giving me a programing error psycopg2: auth not allowed.
so i use the following commands in psql to try and give devuser authorization on this database but here is the problem
when i run GRANT ALL PRIVILEGES ON DATABASE triviaDB to devuser; iget this error:
ERROR: database "triviadb" does not exist
when i quote the db name GRANT ALL PRIVILEGES ON DATABASE 'triviaDB' TO devuser; i get this :
ERROR: syntax error at or near "'triviaDB'"

If the DB name was created with upper cases, you need to use double quotes:
GRANT ALL PRIVILEGES ON DATABASE "triviaDB" to devuser;

Related

Cloud SQL - PostgreSQL - Import failed due to the lack of superuser permission

I'm migrating all the role from my PostgreSQL hosted in GCE VM to Cloud SQL by generating dump file
sudo -Hu postgres pg_dumpall -U postgres --globals-only --file=globals.sql
When I import the same(globals.sql) in Cloud SQL I came across below error:
exit status 3 SET SET SET CREATE ROLE ERROR: must be superuser to alter superusers
Note:
I used postgres user to import this dump file to the cloud sql database.
I'm curious is there any other way to tackle this since postgres user does not have superuser privileges?
I tried executed one query from globals.sql file using cloud shell, below is the output:
postgres=> CREATE ROLE vipinm;
CREATE ROLE
postgres=> ALTER ROLE vipinm WITH NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN NOREPLICATION NOBYPASSRLS;
ERROR: must be superuser to alter superusers
Thanks in advance!
The psql documentation says:
psql returns 0 to the shell if it finished normally, 1 if a fatal error of its own occurs (e.g., out of memory, file not found), 2 if the connection to the server went bad and the session was not interactive, and 3 if an error occurred in a script and the variable ON_ERROR_STOP was set.
So don't set ON_ERROR_STOP.
The error means that you cannot execute the following line from your dump:
ALTER ROLE postgres WITH SUPERUSER INHERIT CREATEROLE CREATEDB LOGIN REPLICATION BYPASSRLS;
That is fine, and you can ignore the error.
This is kind of a bug. As a non-superuser, you can't even reiterate that another role is still not a superuser, as even mentioning anything about superusers even when it would have no effect throws an error. You can get around this by creating the role in its final state, rather than doing the CREATE then ALTER dance that pg_dump likes to do.
CREATE ROLE vipinm WITH NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN NOREPLICATION NOBYPASSRLS;
Alternatively, you could remove from the ALTER statement all the attributes that don't cause any change but merely reiterate the current state of things, leaving:
ALTER ROLE vipinm WITH LOGIN;

getting permission denied for relation in potgresql

I connected to my db using this command
psql -U bm_clients -d Bayne_DB
and then I tried to run this command
Bayne_DB=> GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA abcd TO bm_clients;
For which I received this error
ERROR: permission denied for relation provider_seq
How to resolve this?
Make sure that "Bayne_DB" owns all affected objects.

AWS RDS Postgres error while taking the dump

When I try to take PostgresDump (AWS RDS) the following error I am getting:
ERROR: permission denied for relation dms_stats_detailed
pg_dump: error: query was: LOCK TABLE table_name IN ACCESS SHARE MODE
I am having admin permission though (with Master User).
You need to run pg_dump with a database user (the -U option) that has permission to read the tables you are dumping.

Can postgres role name be `user`?

My username in the personal laptop is user. So running psql from command line throws an error psql: FATAL: role "user" does not exist. This is because the user is a reserved keyword(not sure about the right term) in postgres. Is there a workaround for this problem?
Trying to create a role user errors out for the same reason.
postgres=# CREATE USER user;
ERROR: syntax error at or near "user"
LINE 1: CREATE USER user;
^
You need to quote reserved words. Try CREATE USER "user"

Cant create postgres base type (with hstore/pgcrypto extensions) on amazon RDS

We are moving from our own native postgres installation on an EC2 instance to amazon RDS for postgres. And the data migration is done via dump and restore like this:
pg_dump -U postgres test1_main> test1_main.dump
psql -U postgres -h <rds end point> -p 5432 test1_main < test1_main.dump
On restore, we see failures saying:
CREATE SCHEMA
ALTER SCHEMA
ERROR: must be owner of language plpgsql
ALTER LANGUAGE
SET
CREATE TYPE
ALTER TYPE
ERROR: must be superuser to create a base type
ERROR: permission denied for language c
ALTER FUNCTION
ERROR: permission denied for language c
ALTER FUNCTION
ERROR: must be superuser to create a base type
.....
ERROR: permission denied for language c
ERROR: function pgcrypto.armor(bytea) does not exist
ERROR: permission denied for language c
And so on!
We have added the hstore and pgcryptop extensions to template1 database on our Amazon RDS instance[1] so we have these extensions but we cant create a type because creating a base type in postgres 9.3 needs superuser[2]. postgres user is disallowed to do this and the amazon RDS documentation says:
When you create a DB instance, the master user system account that you
create is assigned to the rds_superuser role. The rds_superuser role
is similar to the PostgreSQL superuser role (customarily named
postgres in local instances) but with some restrictions
rdsadmin is the superuser but I cant log in with rdsadmin.
oncall#ip-10.144.xx.xxx:~> psql -U rdsadmin -h <rds end-point> -p 5432
psql.bin: FATAL: pg_hba.conf rejects connection for host "10.144.xx.xxx", user "rdsadmin", database "rdsadmin", SSL on
FATAL: pg_hba.conf rejects connection for host "10.144.xx.xxx", user "rdsadmin", database "rdsadmin", SSL off
Please help.
[1] http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#SQLServer.Concepts.General.FeatureSupport
[2] http://www.postgresql.org/docs/9.3/static/sql-createtype.html