postgres@vmi465483:~$ systemctl restart postgresql.service
Failed to restart postgresql.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
See system logs and 'systemctl status postgresql.service' for details.
postgres@vmi465483:~$
This is because you are running the command as user postres.
Login as user “root”, you will be able to restart postgres with command
CREATE USER USER_NAME_HERE WITH PASSWORD 'BAPT788HZutBdV';
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO USER_NAME_HERE;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO USER_NAME_HERE;
GRANT USAGE ON SCHEMA public TO USER_NAME_HERE;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA DB_NAME_HERE TO USER_NAME_HERE;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA DB_NAME_HERE TO USER_NAME_HERE;
GRANT ALL PRIVILEGES ON DATABASE DB_NAME_HERE TO USER_NAME_HERE;
psql DB_NAME_HERE -c "GRANT ALL ON ALL TABLES IN SCHEMA public to USER_NAME_HERE;"
psql DB_NAME_HERE -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA public to USER_NAME_HERE;"
psql DB_NAME_HERE -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to USER_NAME_HERE;"
Creating a User and Database using psql
su - postgres
createuser USERNAME_HERE
createdb --encoding=UTF8 --owner=USERNAME_HERE DB_NAME_HERE
If you don’t have PostgreSQL installed, you can use docker, pull the appropriate version of docker image, in this case i used version 13.5, same version used by Amazon RDS, then run
CREATE USER USER_NAME_HERE WITH PASSWORD 'PASSWORD_HERE';
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO USER_NAME_HERE;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO USER_NAME_HERE;
GRANT USAGE ON SCHEMA public TO USER_NAME_HERE;
By default user “postgres” have full access on PostgreSQL. To create a user, run
su postgres
createuser -P USERNAME
To create a database, run
createdb -T template0 -E UTF8 -O USERNAME DBNAME
You can see help with
postgres@ok-vm:~$ createdb --help
createdb creates a PostgreSQL database.
Usage:
createdb [OPTION]... [DBNAME] [DESCRIPTION]
Options:
-D, --tablespace=TABLESPACE default tablespace for the database
-e, --echo show the commands being sent to the server
-E, --encoding=ENCODING encoding for the database
-l, --locale=LOCALE locale settings for the database
--lc-collate=LOCALE LC_COLLATE setting for the database
--lc-ctype=LOCALE LC_CTYPE setting for the database
-O, --owner=OWNER database user to own the new database
-T, --template=TEMPLATE template database to copy
-V, --version output version information, then exit
-?, --help show this help, then exit
Connection options:
-h, --host=HOSTNAME database server host or socket directory
-p, --port=PORT database server port
-U, --username=USERNAME user name to connect as
-w, --no-password never prompt for password
-W, --password force password prompt
--maintenance-db=DBNAME alternate maintenance database
By default, a database with the same name as the current user is created.
Report bugs to <pgsql-bugs@postgresql.org>.
postgres@ok-vm:~$