JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
Use this method to back up your hub database and then restore it at a later time.
If you want to move the backed-up database to a hub on a different architecture, or restore into a different version of CodeSonar, a different process is required. See Relocating the Hub (Different Machine).
We recommend using streaming replication ("warm standby") to back up your hub in preference to using pg_dump, which can be very slow (especially if the hub is in use). This backup method involves establishing a standby server that continuously receives changes from the hub and updates accordingly. Restoring the hub from this kind of backup involves creating a new hub, swapping in the warm standby database directory, and then promoting it to be the new primary database.
One big advantage of this approach is that its time and space costs are much lower than those for pg_dump. The pg_dump approach is linear in the size of the entire hub every time you do it, so if you did daily backups, they might each take most of a day. With this approach, you get backups more frequently than daily, but at a fraction of the cost.
For full information about continuous archiving, see the PostgreSQL documentation.
In this section (and throughout this manual), $CSONAR indicates the CodeSonar installation directory.
The CodeSonar command lines in this task require the following permissions.
The hub's default role-permission settings have the following consequences.
| hub shutdown and info commands |
If special
user Anonymous has
G_HUB_INFO and G_HUB_SHUTDOWN permissions, you will
not need to provide credentials to authenticate and authorize
these commands. Otherwise, you will need to provide suitable hub user account credentials when you execute the corresponding command lines or load the corresponding hub command URLs. See Hub Authentication: Authenticated codesonar Subcommands for more information. |
|---|---|
| HTTP Settings |
Special
user Anonymous is always
treated as if it does not have G_ADMINISTER_HTTP_SETTINGS permission,
even if its assigned roles would otherwise confer it.
Therefore, you will always need to sign in to the hub GUI as a
user with G_ADMINISTER_HTTP_SETTINGS permission in
order to change HTTP settings.
See RBAC: Role-Permissions: Special User Permission Adjustments for more information. |
| SQL Console | If special
user Anonymous has G_SQL_CONSOLE permission, you will not need to provide
credentials to use the hub GUI SQL console. Otherwise, you will need to sign in to the hub GUI as a user with G_SQL_CONSOLE permission in order to perform the SQL steps. User Administrator should typically have G_SQL_CONSOLE permission. |
Before you start, do the following.
The following instructions are based on the following scenario.
| Hub | machine name | hubmachine |
|---|---|---|
| interface | [::] | |
| port | 7340 | |
| directory | hubpath/to/my_hubdir | |
| home page | http://hubmachine:7340 | |
| Standby server | name | standbymachine |
| backup directory | sbpath/to/standbydir |
As with all backup strategies, do a dry run to test your backup and restore procedures before going live.
To back up, you will establish the standby server. This requires actions on both hubmachine and standbymachine.
All of these operations are performed on the hub and its database.
To prepare the hub for backup, do the following.
select version();
CREATE USER replicator REPLICATION LOGIN PASSWORD NULL
SELECT u.usename AS "User Name" FROM pg_catalog.pg_user u;
max_wal_senders = 4 wal_keep_size = 160 wal_sender_timeout = 60s max_replication_slots = 4 wal_level = replica
# Codesonar: START local access hostssl cshub cshubuser ::1/128 cert clientcert=verify-full # Codesonar: END local access # Codesonar: START shared access hostssl cshub cshubuser ::/0 cert clientcert=verify-full hostssl cshub cshubuser 0.0.0.0/0 cert clientcert=verify-full hostssl cshub cshubuser ::/0 cert clientcert=verify-full # Codesonar: END shared access # # Replicator SSL: START hostssl replication replicator 0.0.0.0/0 cert clientcert=verify-full hostssl replication replicator ::/0 cert clientcert=verify-full hostssl cshub replicator ::/0 cert clientcert=verify-full # Replicator SSL: END
SELECT pg_reload_conf();
SELECT * from pg_create_physical_replication_slot('standby1');
All of these operations are performed on standbymachine.
| Windows |
set PGSSLCERT=sbpath\to\replicator.crt
set PGSSLKEY=sbpath\to\replicator.key $CSONAR\third-party\postgresql\inst\bin\pg_basebackup.exe ^ -D sbpath\to\standbydir -R -S standby1 -h hubmachine -p <db_port> -U replicator -X s |
|---|---|
| Other Systems |
PGSSLCERT=sbpath/to/replicator.crt PGSSLKEY=sbpath/to/replicator.key
$CSONAR/third-party/postgresql/inst/bin/pg_basebackup
\
-D sbpath/to/standbydir -R -S standby1 -h hubmachine -p <db_port> -U replicator -X s |
The above reflects the command structure for the current version of CodeSonar. If you have a different version of CodeSonar that uses a different version of PostgreSQL, use the version number you obtained in part A to select version-specific pg_basebackup documentation.
| -D sbpath/to/standbydir | Store the backup in directory sbpath/to/standbydir. This directory does not have to already exist. If it does exist, it must be empty. |
| -R | Create standby.signal and append connection settings to sbpath/to/standbydir/postgresql.auto.conf. |
| -S standby1 | Use the standby1 replication slot that you created earlier. |
| -h hubmachine | The primary database is hosted on hubmachine. |
| -p <db_port> | The primary database is listening on port <db_port>. |
| -U replicator | Connect to the primary database as the special replicator user that you created earlier. |
| -X s | Stream the transaction log while the backup is created. |
The command will continue to run until the base backup has been completed.
| Windows |
dir sbpath\to\standbydir
|
|---|---|
| Other Systems |
ls sbpath/to/standbydir
|
| Windows |
type sbpath\to\standbydir\postgresql.auto.conf
|
|---|---|
| Other Systems |
cat sbpath/to/standbydir/postgresql.auto.conf
|
| Windows |
$CSONAR\third-party\postgresql\inst\bin\postgres.exe
-D sbpath\to\standbydir
|
|---|---|
| Other Systems |
$CSONAR/third-party/postgresql/inst/bin/postgres
-D sbpath/to/standbydir
|
To confirm that the hub is streaming data, you can use an SQL query.
SELECT * FROM pg_stat_replication;
To confirm that the standby server is receiving the streamed data, inspect the timestamps and file sizes in the sbpath/to/standbydir directory. Note that if there is no hub activity, the only changes will be periodic updates to sbpath/to/standbydir/pg_logical/reporigin_checkpoint.
Restoring your database will involve starting a brand new hub,
swapping in the warm standby database directory, and then promoting
it to be the new primary database.
Carry out the hubmachine steps as
the system user or service account that is usually
responsible for starting the hub.
| Windows |
Use the remote file transfer method recommended by your
local system administrator to perform the copy:
|
|---|---|
| Other Systems |
scp -r standbymachine:sbpath/to/standbydir
recpath/to/newhub_dir/pgdata
|
SELECT * from pg_create_physical_replication_slot('standby1');
Upgrading a CodeSonar hub that is backed up using streaming
replication involves some additional steps before and after
the hub upgrade.
Carry out all these steps as the system user or service account that
is usually responsible for starting the
hub.
Perform the following steps on standbymachine to suspend archiving and move your existing archive so that you can establish a new one after upgrading the hub.
After upgrading the hub, reestablish the standby by working through all the steps of B. Set up the standby server, above.
In particular, you may be interested in: