Pgsql Database Backup

Hello,

If i create 2 db under user ‘Auth’:

  • mysql (maria)
  • pgsql

Hestia create these:

  • Auth_maria_DB
  • auth_pgsql_db (hestia removed the capital letters)

Then I create a backup of Auth:
v-backup-user ‘Auth’ ‘yes’

[…]

– DB –
2024-08-31 12:16:18 Auth_maria_DB (mysql)
/backup/tmp.uDTjA3nRSG/db/Auth_maria_DB/Auth_maria_DB.mysql.sql : 41.18% ( 1394 => 574 bytes, /backup/tmp.uDTjA3nRSG/db/Auth_maria_DB/Auth_maria_DB.mysql.sql.zst)
2024-08-31 12:16:18 auth_pgsql_db (pgsql)
/backup/tmp.uDTjA3nRSG/db/auth_pgsql_db/auth_pgsql_db.pgsql.sql : 62.20% ( 545 => 339 bytes, /backup/tmp.uDTjA3nRSG/db/auth_pgsql_db/auth_pgsql_db.pgsql.sql.zst)
2024-08-31 12:16:18 *** 2 databases ***

[…]

2024-08-31 12:16:21 Local: /backup/Auth.2024-08-31_12-16-20.tar

[…]

Then I delete both databases and try to restore them:
v-restore-user ‘Auth’ ‘Auth.2024-08-31_12-16-20.tar’ ‘no’ ‘no’ ‘no’ ‘Auth_maria_DB’ ‘no’ ‘no’ ‘yes’
v-restore-user ‘Auth’ ‘Auth.2024-08-31_12-16-20.tar’ ‘no’ ‘no’ ‘no’ ‘auth_pgsql_db’ ‘no’ ‘no’ ‘yes’

The restore appear to add an additional Auth_ for the new Postgresql database, and is OK for maria sql.

Am I doing something wrong, or is this a bug?

Hi @visio,

Well, Hestia doesn’t remove the capital letters, PostgreSQL does it if the db name is not quoted. The problem quoting the db name to keep the db name case is that all the queries to that database must enclose the db name with quotes “Auth_pgsql_db” and that would be a problem if the software you run against the db doesn’t use them.

I wouldn’t allow capital letters in users so this won’t happen again :wink: But yes, it is a bug because recovering the db doesn’t take in account that a user can have capital letters in the name but PostgreSQL created the db name as lowercase. I’ll try to take a look but now I don’t have a machine to perform the tests.

Thanks for the feedback.

So I attempted this workaround and created another user ‘auth’ all lowercase (side note: I had both Auth and auth as users! Not sure if it’s desirable that usernames are case sensitive)

I test out the backup and it is created with the right name.

However, the owner of all the tables in the database where changed to ‘postgres’ while they should have remained unchanged.

I had to change them back manually.

In my opinion, no, it isn’t desirable. I would force user names to be lowercase to avoid issues like this.

Indeed, if you use useradd there is no problem to create the user Auth but if you use adduser, you will see this message:

In Debian:

# adduser Auth
adduser: Please enter a username matching the regular expression
            configured via the NAME_REGEX configuration variable.  Use the
            `--allow-bad-names' option to relax this check or reconfigure
            NAME_REGEX in configuration.

In Ubuntu:

# adduser Auth
adduser: Please enter a username matching the regular expression configured
via the NAME_REGEX[_SYSTEM] configuration variable.  Use the `--force-badname'
option to relax this check or reconfigure NAME_REGEX.

I suppose it is because there was already a user auth in PostgreSQL (remember that PostgreSQL uses lowercase for all).

We should lower case Postgresql for sure …

1 Like