Unable to connect to local Postgres via GUI - postgresql

I recently ran a Postgres via Docker where in I have a Dockerfile that copies an init script to add new user, enable UUID extension, created database and grant privileges.
I can login using the default user "postgres" but not the second account "XXX_itsm". It says FATAL: database "XXX_itsm" does not exist.
What I'm planning to do is just create a database but another problem occurred when connecting via GUI (Postico / TablePlus).
Which leads me to the following questions:
What is the proper way of creating a user? (I have this current init script in entrypoint)
NOTE: I have the variables defined in Dockerfile ENV DB_USER DB_PASS DB_NAME
Why it's only allowing me to login in GUI with the default user?

Related

How to change the default username a postgresql db is connecting to?

I've seen posts that describe how to set postgresql server to connect to your own user but I could not find any posts that describe how to make psql connect to the default postgres user instead by default. In my case, right after installation when I open up psql, it connects to the username with the name same as my windows user instead of the postgres user that I want it to connect to.
As documented in the manual you can define an environment variable PGUSER which is used instead of your Windows user as the default user for all Postgres command line tools.
You can create a psqlrc.conf file with following data:
\c <database> <user>
Doc says:
The user's personal startup file is named .psqlrc and is sought in the
invoking user's home directory. On Windows, which lacks such a
concept, the personal startup file is named
%APPDATA%\postgresql\psqlrc.conf. The location of the user's startup
file can be set explicitly via the PSQLRC environment variable.

createdb: permission denied to create database

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.

Root user can't connect to any database with MongoDB

I'm using MongoDB with Docker and want to automate the database creation.
I found that when passing MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD environment variables to the docker run command I can create a new root user on the admin database.
My issue starts when I'm trying to create a new database and create collections in it.
I wrote a script that selects the admin database, authenticate into the mongo service and creates new db, but for some reasons I can not access the database with my credentials..
use admin;
db.auth('myuser', 'mypassword');
use newDatabase;
db.createCollection('newCol');
when trying to authenticate to newDatabase with the given credentials (myuser and mypassword) I found that I do not have the needed permissions to the db.
What did I do wrong? How can I do it automatically anyway?
I just understood that the root cannot access the other databases for some reasons, so I used db.createUser and created a new user just for the new database.

Can't see my databases in OpenERP

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/

User authorization in DB2

I am using win Vista, and I am trying to backup some Database under DB2.
I am logged in using the Administrator user, and whenever I try to issue the backup command in the "command line processor", I get the following message:
SQL1092N "ADMINISTRATOR" does not have the authority to perform the requested command. SQLSTATE=00000
BTW, I have created a username/password pair (db2admin) while installing the DB2 server.
So, Will this problem will be get solved if I use the db2admin user? And how to connect to the server (local server BTW) using the db2admin user ?
I had this problem recently and this seemed to do the job:
Attach to your [local] node. (the value of your DB2INSTANCE environ variable, mine was 'DB2'):
attach to DB2 user db2admin using mypassword;
If this isn't enough (it didn't seem to be with me), you can also specify the user and password with backup and restore commands:
restore database mydbname user db2admin using mypassword from C:\BACKUPS taken at 20100823132457;
Or manually create the db2admin user with a password on Windows. But I'm not sure if that's the correct option here.