Running PostgreSQL server on Void Linux. After installing ran initdb
as OS user 'postgres':
[user@host]$ sudo -u postgres -i
$ initdb -D '/var/lib/postgresql/data'
Received output:
creating directory /var/lib/postgresql/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting dynamic shared memory implementation ... posix creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... locale: Cannot set LC_MESSAGES to default locale: No such file or directory ok syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using: pg_ctl -D /var/lib/postgresql/data -l logfile start
I've then proceeded to create the service, grant the ownership to 'postgres' and start it:
[user@host]$ ln -s /etc/sv/postgresql /var/service
[user@host]$ sudo chown postgres: /var/service/postgresql
[user@host]$ sudo sv start postgresql
[user@host]$ ls -l /var/service/postgresql
lrwxrwxrwx 1 postgres postgres 18 nov 2 17:05 /var/service/postgresql -> /etc/sv/postgresql
Running:
[user@host]$ sudo -u postgres psql ...
will give me the following error:
psql: FATAL: role "postgres" does not exist
I've tried granting ownership of /etc/sv/postgresql
to 'postgres', but no luck.
These were my sources:
https://wiki.voidlinux.eu/PostgreSQL
PostgreSQL error: Fatal: role "username" does not exist
I do not know what to do next.
EDIT: Stumbled upon psql: FATAL: role "postgres" does not exist. Cannot run psql -l
because I get the same error, no matter which user I run psql
as.
3 Answers 3
Not a full answer, but consider the manual about initdb
here:
-U
username
--username=
username
Selects the user name of the database superuser. This defaults to the name of the effective user running
initdb
. It is really not important what the superuser's name is, but one might choose to keep the customary name postgres, even if the operating system user's name is different.
Meaning ...
When running
initdb
as OS userpostgres
, the initial DB superuser role ispostgres
as well - in standard Postgres. I have heard of systems bending this rule ...You should be able to force the name
postgres
with--username=postgres
for the initial superuser - unless your package seriously messed with all this.
-
1Wow, this pointed me at the right direction, all right. I knew I saw that
-U
flag somewhere and it was from here: stackoverflow.com/questions/50746147/… I might have misread Laurenz's answer there, but I raninitdb -U UTF8 -D /var/lib/postgresql/data
and guess what the initial DB superuser role was. Anyway, I ended up almost crashing my entire system due to exhaustion. A fairly productive day. Thank you for your dedication Erwin, your help is much appreciated.Jakov– Jakov2018年11月03日 00:50:12 +00:00Commented Nov 3, 2018 at 0:50 -
@Jakov:
-U UTF8
. Ouch. Was meant to be-E UTF8
I assume? Sorry for your day lost due to one sneaky scrambled letter. Then again: If you had shown your actual command in the question to begin with, we might have saved half your day ...Erwin Brandstetter– Erwin Brandstetter2018年11月03日 01:24:36 +00:00Commented Nov 3, 2018 at 1:24
#type this:
sudo -u postgres -i
#it will prompt you to enter your password.type your password in. Voila! Ure in.
#If you wish to change to your desired username, make sure you do that from within the loggedin default postgres you just entered.
-
Wasn't the first thing the poster said was they tried sudo -u postgres -i?Anthony Genovese– Anthony Genovese2022年08月01日 16:40:34 +00:00Commented Aug 1, 2022 at 16:40
Maybe you have used "initdb" utility to initiate your database cluster, or second database instance. You need to use like this: initdb -D "location of data directory" --username=youruser -W
--username=youruser This tells the initdb utility to set yourusername as the super user for your new db cluster. If you do not use this then there will be no Superuser for your database and you will not be able to connect to it.
You can watch related video here: https://www.youtube.com/watch?v=tdijTz8n5ok
-
This was my problem, spot on. Thank you!atraudes– atraudes2024年05月09日 16:02:26 +00:00Commented May 9, 2024 at 16:02
role "postgres" does not exist
: there is no database role named "postgres". Is it the only Postgres installation on the same machine? (So you are sure to connect to the right instance?) If so, the question is: which database role is set up by your installation. I don't know Void Linux or the XPBS package manager enough to say more. Might be better suited for superuser.SE or unix.SE.initdb
, and then connect with the OS user of the same name to be granted access by the "trust" authentication method. Obviously not "postgres" (which would be the sane default).session_replication_role = 'origin'
. Not much use of that, I feel.:%s/XPBS/XBPS/g