How to connect to PostgreSQL Streaming Replication Protocol with odbc? - postgresql

Connection to postgres logical replication protocol works with psql like this
psql "dbname=postgres replication=database"
How can I set "replication=database" parameter when connecting with odbc?

Related

Postgres 9.4: Replicate only one database from one instance to another

I have postgresql 9.4 running in 5432 port with 2 databases. Now I want to create another instance in 5433 port (passive) and replicate only one database from 5432 instance (active). All table and data changes in database in 5432 instance (active) should replicate to the database in 5433 instance (passive).
I also have to create another database in 5433 instance (passive) and do CRUD operation in new database
Do we have a way to do this in postgres?
Streaming replication cannot do that, and logical replication (which could do that) was introduced in v10.
So your best option would be to upgrade.
Apart from that, you'd have to resort to legacy trigger-based replication solutions like Slony.

"No such database" error on pgAdmin when connecting through pgbouncer

I have configured pgbouncer on server A(port 6432, host addr: 10.XX.XX.92) that will accept the connections for postgres server running on server B(port 5433, host addr:10.XX.XX.90). This postgres server has 2 databases.(postgres and db1)
I have 2 different type of users(user1, user2) that will connect to same database(db1). These both users have different set of permissions on db1.
Below is the sample of how I have configured pgbouncer.ini file.
database1 = host=10.XX.XX.90 port=5433 user=user1 password='pwd1' dbname=db1
database2 = host=10.XX.XX.90 port=5433 user=user2 password='pwd2' dbname=db1
Now when I try to connect to this database through pgAdmin it gives me an error of "No such database" .
Below are the connection variables that I used to connect through pgadmin for user1.
host = 10.XX.XX.92
port = 6432
maintenance database = database1
username = user1
password = pwd1
But when I use same variables and try to connect using DBeaver or psql, I am able to connect to the database db1 successfully.
Does anyone know if this is just pgAdmin issue or am I missing something here.
Note: There is one more thing I tried. If in the pgbouncer.ini, I name the database variable(database1) same as actual database name(db1), pg
Admin lets me connect to the database. This would have worked for me if I just had one user connecting to the database but I have two users and they both can't have same connection name in the config file.
Have a try here :
https://stackoverflow.com/a/41500185/5341247
add this to your connection string :
EntityAdminDatabase=DATABASE_NAME

How to get the PostgreSQL db backup from slave if master down

I have setup PostgreSQL hot stand by replication on Ubuntu. I need to know if master DB server is down, then how to get the backup from the slave.
I have tried this command
pg_dump testdb > /var/lib/postgresql/20190306.bak -p 5433
I got this error:
pg_dump: [archiver (db)] connection to database "channeldb" failed:
FATAL: role "root" does not exist
This specific error has nothing to do with this being a standby server.
Rather, you forgot to use the -U option to specify the database user, so pg_dump assumes it is the same as the operating system user.
Don't use the root user for anything but administrative activities!

Realm Data Connector with Heroku Postgres: must be superuser or replication role to use replication slots

I'm following Realm Postgres Connector reference for syncing our Realm database with our Heroku PostgreSQL database: https://docs.realm.io/platform/using-synced-realms/server-side-usage/data-integration/postgres-connector#realm-data-adapter
It's working fine locally as I could connect to the PG local database withsuperuser role in order to use replication slots. However, superuser or replication roles cannot be set on Heroku PostgreSQL database, hence leading to the following PG error:
PGRES_FATAL_ERROR: ERROR: must be superuser or replication role to use replication slots
Does anybody already got Realm Postgres Connector working with a Heroku PG database? Or could think of a workaround?
Thanks for your help!
Lucas
Heroku support confirmed that there is currently no way to use replication roles:
Unfortunately, we do not allow creation of new replication slots by customers, as replication users are very privileged in Postgres, almost to the superuser level.
Hence I've decided to migrate to Amazon RDS. Here is a great article on how to perform such migration: https://www.lewagon.com/fr/blog/how-to-migrate-your-heroku-postgres-database-to-amazon-rds

What is JDBC counterpart of Postgres' "\connect" command?

I'm trying to execute following Postgres 9.6 commands over JDBC connection
CREATE USER my_db WITH SUPERUSER PASSWORD 'my_db';
CREATE DATABASE my_db;
GRANT ALL PRIVILEGES ON DATABASE my_db TO my_db;
\connect my_db; -- THIS ONE FAILS
SET ROLE my_db;
CREATE SCHEMA my_db AUTHORIZATION my_db;
"\connect" command fails as not recognized. Is there way to connect other database staying within the same JDBC connection?
UPD: "CONNECT TO ..." and "EXEC SQL CONNECT TO ..." also fail.
Backslash commands are not PostgreSQL SQL commands, they're commands in the psql command-line utility. Behind the scenes, \connect just closes the connection and opens a new one.
PostgreSQL its self does not have any way to switch databases on a connection.
Disconnect and reconnect to the other DB.