Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot initialize postgresql database #902

Closed
kovmir opened this issue Mar 24, 2024 · 7 comments
Closed

Cannot initialize postgresql database #902

kovmir opened this issue Mar 24, 2024 · 7 comments
Labels

Comments

@kovmir
Copy link

kovmir commented Mar 24, 2024

I pre-created tinode database, but it fails saying the database already exists:

$ ./init-db -data=./data.json
2024/03/24 07:17:44 Database adapter: 'postgres'; version: 113
2024/03/24 07:17:44 Database not found. Creating.
2024/03/24 07:17:45 Failure: ERROR: database "tinode" already exists (SQLSTATE 42P04)

I dropped the database, but it still complains:

./init-db -data=./data.json
2024/03/24 07:19:53 Database adapter: 'postgres'; version: 113
2024/03/24 07:19:53 Failed to init DB adapter: failed to connect to `host=localhost user=tinode database=`: server error (FATAL: database "tinode" does not exist (SQLSTATE 3D000))

My tinode.conf snippet:

"postgres": {
                                // PostgreSQL connection settings.
                                "User": "tinode",
                                "Passwd": "ufuB1AdBSp-NtHuv",
                                "Host": "localhost",
                                "Port": "5432",
                                "DBName": "tinode",
                                
                                // DSN: alternative way of specifying database configuration, passed unchanged
                                // to the driver. See https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
                                // "dsn": "postgresql://postgres:postgres@localhost:5432/tinode?sslmode=disable&connect_timeout=10",

Debian bookworm, tinode version 0.22.12, PostgreSQL 16.

@kovmir kovmir added the bug label Mar 24, 2024
@or-else
Copy link
Contributor

or-else commented Mar 24, 2024

Unfortunately PgSQL is somewhat brain damaged: the database connection must specify an existing database, and if no database is provided, it defaults to the same database name as the connecting user name. That's why we provide sample connection as

"User": "postgres",
"Passwd": "postgres",

The user postgres matches an existing database postgres.

If you do not want to use user postgres, then create another user with any name other than tinode. Say, create user tinodeadmin, create an empty database tinodeadmin and everything will work.

@or-else or-else closed this as completed Mar 24, 2024
@kovmir
Copy link
Author

kovmir commented Mar 24, 2024

... create user tinodeadmin, create an empty database tinodeadmin

This produces exactly the same errors.

@or-else
Copy link
Contributor

or-else commented Mar 24, 2024

Are you sure you did it right? Show it.

@kovmir
Copy link
Author

kovmir commented Mar 24, 2024

I finally got it, User and DBName within the config file must not match:

$ ./init-db
2024/03/24 17:59:36 Database adapter: 'postgres'; version: 113
2024/03/24 17:59:36 Database not found. Creating.
2024/03/24 17:59:36 Failure: failed to connect to `host=localhost user=tinodeadmin database=tinode`: server error (FATAL: remaining connection slots are reserved for roles with the SUPERUSER attribute (SQLSTATE 53300))

Now I get a different error, but I think it is PostgreSQL-related.

@kovmir
Copy link
Author

kovmir commented Mar 24, 2024

Seems like there is enough connections, why does it complain?

postgres=# show max_connections;
 max_connections
-----------------
 100
(1 row)

postgres=# show reserved_connections ;
 reserved_connections
----------------------
 0
(1 row)

@or-else
Copy link
Contributor

or-else commented Mar 24, 2024

This is unrelated to Tinode. Please use a different venue to get Postgres administration support.

@kovmir
Copy link
Author

kovmir commented Mar 24, 2024

OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants