I have a warm-standby postgres server and I store some information about the server itself in the database. So, the information kept in this table should be different between the primary and standby. However, once it is set to standby mode these values can no longer be updated. Is there any way to set specific tables/schemas to be writable while in standby mode?
Related
I'm using PostgreSQL 12. I have set up replication. And also set up the versioning history trigger for all the tables in the replica database to store audit history. But here in one of the tables, I'm storing the based64 content and it is not replicated properly in the replica database and it is stopping the database server.
It is throwing the error.
FATAL: the database system is in recovery mode
It is not happing in every case.
Base64(XML) Content in Master Database
Base64(XML) Content(InValid Conent) in Replica Database
Can anyone help me with why it is happening? Thanks in advance.
Below are the steps for configuration the replication:
Publication Databaase:
Creating the `REPLICA IDENTITY and assigning it to each table
Creating replication slot and publication :
select 1 from pg_create_logical_replication_slot('pubqablankdb','pgoutput')
create publication pubqablankdb for all tables
Subscription Database:
Creating Subscription:
CREATE SUBSCRIPTION subqablankdb CONNECTION 'host=1.1.1.1 port=5432 user=postgres password=xxxxx dbname=qablankdb' PUBLICATION pubqablankdb with (create_slot= false,slot_name = 'pubqablankdb', enabled = true);
Please see below the database info. (UTF8 encoding)
Master DB: qablankdb
Replica DB: auditlog
I have a client website that has a Postgres backend which I consider as my remote database. I use FDWs to connect from my local database to the remote DB.
So what I have is :
Remote DB ->remote Schema -> Has a table called remote_work_packages
On my database, this would after I create an FDW server -
Local DB -> Local schema -> foreign table foreign_work_packages
Now as I said the client website connects to the Remote DB , and whenever there is an INSERT, UPDATE or DELETE into remote_work_packages, then I want some functions to be triggered on my local schema.
Please note , I do not have access to create a trigger on the Remote table.
Is there a way this can be achieved. I know since release 9.4, that it is possible to create triggers on foreign tables. But there is no way I could find out how to track activity on the remote itself. Is there a way to track staying on the local DB. Please advise.
One of several databases in a Postgres 10.15 cluster has been set to be a system database. The mechanism that caused this is unknown, though it may have happened at the same time that the database was converted to a template by updating the pg_database table. The pg_database table does not have a setting to control whether or not a database is a system database, however, and I cannot find any documentation describing how to set (or unset, which is what I really want to do) the system database flag.
The idea of a “system database” is foreign to PostgreSQL, it is an artifact of pgAdmin.
PostgreSQL does have the notion of a “template database”, that is a database that is intended to serve s template in CREATE DATABASE. You turn a database to a template database with
ALTER DATABASE some_db IS_TEMPLATE TRUE;
For such a database it is also a good idea to forbid connections, because you can only use a database as template if nobody else is connected to it:
ALTER DATABASE some_db ALLOW_CONNECTIONS FALSE;
I've recently implemented streaming replication and need to create a "report user" for the replica. This user will be used to access the database via ODBC to generate reports with.
On the slave (replica DB), It seems I cannot create new users. I also need to change the password of 'postgres' user on the slave. Here's what I've tried and the errors I get:
CREATE ROLE readaccess;
ERROR: cannot execute CREATE ROLE in a read-only transaction
\password postgres
ERROR: cannot execute ALTER ROLE in a read-only transaction
How can I create a new read only user for my replica?
How can I change the password of the user 'postgres' on the replica?
Note: I do realize that for a replica, you can (or should) only have read-only access.
Thank you.
As you have discovered, the replica is read-only anyway. So you have a few choices.
Just use any of your accounts from the primary. They will have the same permissions on the replica (except that they cannot change data).
Create a special user that only has 'select' permissions on the primary, and that user flow through to the replica.
As for having different passwords on the primary and replica, you can't. If that is a hard requirement for you, you'll have to look into "logical replication".
I want to shut down one database in a db2 instance with multiple dbs.
I don't want to deactivate the db as it will reconnect when I try to connect. It should be completely shut down so I get a connection error when trying to connect to the db.
This is not a programming question so it can be viewed as off topic.
There are different techniques, each has advantages/disadvantages.
You can quiesce the database and later unquiesce it.
or you can revoke connect rights, and later grant them, but this depends on how well your role separation is done.
or you force off existing applications and then connect in exclusive mode as the instance owner (provided that your applications NEVER connect with instance-owner credentials).
One trick you could use is to temporarily recatalog the database you want to deactivate under a different name; this will prevent applications from connecting to it using the original name, regardless of the authority they use.
First, determine the database path by looking at its catalog entry:
db2 list db directory
The value of the "Local database directory" property is what you need.
Now you can recatalog the database:
db2 uncatalog db orig_db
db2 catalog db orig_db as foobar on <path>
where <path> is the local database directory determined previously.
Once you force all applications currently connected to the database in question you will be able to deactivate the database:
db2 list applications
db2 "force application (<app id 1>, <app id 2>,...)
db2 deactivate db foobar
Later on you can restore the catalog entry to its original value:
db2 uncatalog db foobar
db2 catalog db orig_db on <path>