If I create a DB user with
"sudo -u postgres psql -c "CREATE USER guacamole PASSWORD 'PW'; GRANT ALL PRIVILEGES ON DATABASE guacamole TO guacamole"
this user disappears after reboot. How can I make this user/command persistent, so that I do not need to recreate after reboot
thanks
Related
I need to use root user to run scripts at crontab, for example to read and write on all /home folders.
But something that I need to do also in the shell script is to run psql. Problem:
my user (me = whoami and not is root) can run for example psql -c "\l"
the root user not works (!) with psql -c "\l"... And error not make sense "psql: error: could not connect to server: FATAL: database "root" does not exist".
How to enable root to run psql?
PS: looking for a kind of "GRANT ALL PRIVILEGES ON ALL DATABASES TO root".
root is allowed to run psql, but nobody can connect to a database that doesn't exist.
The default value for the database user name with psql is the operating system user name, and the default for the database is the same as the database user name.
So you have to specify the correct database and database user explicitly:
psql -U postgres -d postgres -l
The next thing you are going to complain about is that peer authentication was denied.
To avoid that, either run as operating system user postgres or change the rules in pg_hba.conf.
I previously asked how to make a backup of a Firebird database in
I need to backup or clone one remote firebird database or export it to Sql server
Now the backup is complete, but when I try to restore it to Firebird on my computer, I get an error.
I use this command:
gbak -r -p 4096 -o e:\mybackup.fbk localhost:e:\bddados.fdb -user sysdba -pas masterkey
The error I receive is
gbak: ERROR:Your user name and password are not defined. Ask your database administrator to set up a Firebird login. gbak:Exiting before completion due to errors
But I test my Firebird locally with this user and password and it's ok. Does the created backup database need to specify in generate command a password or do I need to use the same of the old database?
user and pas[sword] parameters should be before the path to files
gbak -r -p 4096 -o -user sysdba -pas masterkey e:\mybackup.fbk localhost:e:\bddados.fdb
gbak documentation
I created a sql dump using mysql dump but on restoring on another server I get an error 'ERROR 1227 (42000) at line 397: Access denied; you need the SUPER privilege for this operation :
when i checked the line number I see the issue seems to be with part root#localhost, as new server does not have root privileges from the account I am using. If i removed root#localhost it went ahead but I am not sure if its right way by removing root#localhost from the following as there are many places in the sql file it has the reference.
What would be the right way?
/*!50003 CREATE*/ /*!50017 DEFINER=`root`#`localhost`*/ /*!50003 TRIGGER `Update Feeback status in Order` AFTER INSERT ON `customer_ratings`
FOR EACH ROW BEGIN
Fist you can check your access.
1.- Check for your access in the new server
$mysql -u root -p -hlocalhost
Enter password:
2.- show your grants
$mysql>SHOW GRANTS FOR 'root'#'localhost';
To solve the problem you can do this.
1.- stop your services.
service mysqld stop
2.- start your services with "stop grant tables"
mysqld --skip-grant-tables
3.-update the password of user root
$mysql>UPDATE user SET Password=PASSWORD('my_password') where USER='root';
(if you want you can create your user)
$mysql>CREATE USER 'root'#'localhost' IDENTIFIED BY 'password';
4.- Flush the privilages
$mysql> FLUSH PRIVILEGES;
5.- Restart your server
service mysqld start
6.- tray to restore your dump file.
mysql -u root -hlocalhost -p [database_name] < dumpfilename.sql
Hope this help.
I have created a postgres database in postgres named "databaseName". Now I can access this data2database through
su - postgres
and then typing my password
Then I enter into the database through: psql databaseName
I have created users of this database through:
createuser -P userName1
Now I dont want the users of the database to access the database as root user. Now when the users try to login into postgres as
su - postgres -u userName1
or through
psql databaseName -u userName1
I get error...can someone guide me as to how the users can get access to postgres and database without being root user?
Configure pg_hba.conf to accept peer connections over unix sockets or ident connections over host (tcp) connections. If you prefer you can use md5 to use password authentication instead.
By default psql will connect with the same username as your local OS username; this can be overridden by the -U flag, eg:
psql -U myusername thedatabase
Note that it's -U not -u (it's upper case).
This is all covered in detail in the PostgreSQL documentation; see:
Client Authentication
pg_hba.conf
psql
BTW, if you want to run commands as the postgres user, rather than su'ing you can just write:
sudo -u postgres psql
In postgres, how do I change an existing user to be a superuser? I don't want to delete the existing user, for various reasons.
# alter user myuser ...?
ALTER USER myuser WITH SUPERUSER;
You can read more at the Documentation for ALTER USER
To expand on the above and make a quick reference:
To make a user a SuperUser: ALTER USER username WITH SUPERUSER;
To make a user no longer a SuperUser: ALTER USER username WITH NOSUPERUSER;
To just allow the user to create a database: ALTER USER username CREATEDB;
You can also use CREATEROLE and CREATEUSER to allow a user privileges without making them a superuser.
Documentation
$ su - postgres
$ psql
$ \du; for see the user on db
select the user that do you want be superuser and:
$ ALTER USER "user" with superuser;
May be sometimes upgrading to a superuser might not be a good option.
So apart from super user there are lot of other options which you can use.
Open your terminal and type the following:
$ sudo su - postgres
[sudo] password for user: (type your password here)
$ psql
postgres#user:~$ psql
psql (10.5 (Ubuntu 10.5-1.pgdg18.04+1))
Type "help" for help.
postgres=# ALTER USER my_user WITH option
Also listing the list of options
SUPERUSER | NOSUPERUSER | CREATEDB | NOCREATEDB | CREATEROLE | NOCREATEROLE |
CREATEUSER | NOCREATEUSER | INHERIT | NOINHERIT | LOGIN | NOLOGIN | REPLICATION|
NOREPLICATION | BYPASSRLS | NOBYPASSRLS | CONNECTION LIMIT connlimit |
[ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password' | VALID UNTIL 'timestamp'
So in command line it will look like
postgres=# ALTER USER my_user WITH LOGIN
OR use an encrypted password.
postgres=# ALTER USER my_user WITH ENCRYPTED PASSWORD '5d41402abc4b2a76b9719d911017c592';
OR revoke permissions after a specific time.
postgres=# ALTER USER my_user WITH VALID UNTIL '2019-12-29 19:09:00';
Run this Command
alter user myuser with superuser;
If you want to see the permission to a user run following command
\du
You can create a SUPERUSER or promote USER, so for your case
$ sudo -u postgres psql -c "ALTER USER myuser WITH SUPERUSER;"
or rollback
$ sudo -u postgres psql -c "ALTER USER myuser WITH NOSUPERUSER;"
To prevent a command from logging when you set password, insert a whitespace in front of it, but check that your system supports this option.
$ sudo -u postgres psql -c "CREATE USER my_user WITH PASSWORD 'my_pass';"
$ sudo -u postgres psql -c "CREATE USER my_user WITH SUPERUSER PASSWORD 'my_pass';"
alter user username superuser;
If you reached this because you're using Amazon Redshift you CANNOT assign SUPERUSER
ALTER USER <username> SUPERUSER;
Instead assign CREATEUSER:
ALTER USER <username> CREATEUSER;
Apparently, SUPERUSER isn't an available user assignment in Amazon Redshift clusters. I am utterly confused by this.
https://docs.aws.amazon.com/redshift/latest/dg/r_superusers.html
Screenshots showing this:
https://i.stack.imgur.com/uyWXt.png
https://i.stack.imgur.com/ycbeL.png