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.
Related
I've created simple PostgreSQL database on my localhost and connected it to my project. I want to pass the project to someone else and share the same database. Also i want my db to run 24h per day and be accessible without previous switching on.
Let's see. It is a lot of spec. Fortunately, the solution for your problem is simple: move your database from local machine (your PC/laptop) to a network-connected server. Below is step-by-step list of what you need to do:
Find a decent PostgreSQL DB provider (some paid, some free), for example: Amazon RDS , ElephantSQL, Azure PostgreSQL. Then create an instance.
Or you can setup a server and install PostgreSQL. Either works fine.
Change the connection from localhost:5432 to new server. There is no detail on question, so I'll provide an example of connection string:
postgres://{remoteuser}:{password}#{remotehost}:{port}/{dbname}
If your local database already contain data, copy it to new database
pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser dbname
I have accidentally deleted the default "postgres" database from my postgres. I've read that:
Most Postgres servers have three databases defined by default: template0 , template1 and postgres . template0 and template1 are skeleton databases that are or can be used by the CREATE DATABASE command. postgres is the default database you will connect to before you have created any other databases.
I have now created again a postgres database by running CREATE DATABASE postgres.
Do I need to do anything else to basically redo deleting the "postgres" database? Or the current one is basically the same?
Thanks
The database postgres is in no way special. You should use the bootstrap superuser (normally postgres) as the database owner, then the database will be just as good as the original postgres database.
The only difference is that the new database will have an OID ≥ 16384, which identifies it as an object created after cluster initialization. However, a quick look through the source code makes me believe that we don't use that anywhere.
I created an RDS Postgres instance. I'm new to RDS.
db host:
demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com
db identifier:
demodb
Every tutorial says to connect with this URL:
jdbc:postgresql://demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com:5432/demodb
but every time I do I get this error-
FATAl: database "demodb" does not exist.
I am able to connect using this:
jdbc:postgresql://demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com:5432/postgres
Now, while I was excited to connect after I used SQL workbench to create tables and insert data into those tables, a few hours later all my tables and data were deleted/wiped/dropped. Why would this happen? and How can I prevent it from happening in the future?
FATAl: database "demodb" does not exist.
demodb is db instance identifier. It is NOT the name of your database inside of PostgreSQL.
By default RDS PostgreSQL does not create a database for you. It seems to me that you haven't created an actual database when you setup your RDS PostgreSQL.
To create a database at RDS creation there is an option called Initial database name where you should specify the name of the database you want. Otherwise, no database is created, which is a default behavior:
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
I have two POSTGRES databases stored in different servers.
The "Firstdb" is version 9.2 and it is stored in a LAN server, port 5432.
The "Seconddb" is version 10 and it is stored as localhost to my PC, port 5432.
I have access to both of them through pgAdmin4 version 2.0.
I would like to run query between those two databases to compare data.
Any ideas about how this can be done?
Thank you all for your time.
For running federated queries I use most of the time postgres_fdw, which creates a foreign table in the source database. Quite handy but has its caveats when dealing with joins.
An example:
CREATE SERVER my_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'target.host.com', port '5432', dbname 'targetdb');
CREATE USER MAPPING FOR postgres SERVER my_server OPTIONS (user 'postgres');
CREATE FOREIGN TABLE my_foreign_table (
id INT,
desc TEXT
)
SERVER my_server OPTIONS (schema_name 'public', table_name 'target_table');
EDIT based on the comments:
Keep in mind that the source database, as any other application, needs access to the target database and it has to be described at the pg_hba.conf:
host yourdb youruser 0.0.0.0 md5
Another approach is using dblink, which does not create a foreign table but enables you to fire queries directly to the target database and retrieve the result sets just as if it was local.