PostgreSQL® Database Maintenance - WinCC OA-managed Database
Upgrade the Schema
PSQL_upgradeTo<version>.sql
upgrades the schema to the specified version. psql -f <upgrade_script.sql> [-U user] [-h database_host] [-p database_port] <database_name>
For example, to upgrade the schema to the specified version, where the database server is installed on localhost with default port (5432), with the user (etm) and with the database name (winccoa), simply call:
psql -f PSQL_upgradeTo<version>.sql -U etm winccoa
You will then be asked for the password of the user `etm`. For more information about how to connect to the PostgreSQL® database, see (https://www.postgresql.org/docs/current/app-psql.html).
"ALTER ROLE etm
REPLICATION;"
in the database with the admin user
account:psql -U admin_user -h C:/Users/<username>/AppData/Local/.winccoa -p 15432 -c “ALTER ROLE etm REPLICATION;”
pg_basebackup -D <db_target_backup_directory> -U admin_user -h C:/Users/<username>/AppData/Local/.winccoa -p 15432 -Ft -z -c spread -R -P
pg_basebackup -D <db_target_backup_directory> -U admin_user -h $HOME/.winccoa -p 15432 -Ft -z -c spread -R -P
Create a Backup
To backup your complete PostgreSQL® database, proceed as follows.
Prerequisite: WinCC OA project is running and PostgreSQL® database is accessible.
- In a "WinCC OA managed PostgreSQL"
Database backend configuration, the following parameters are set to ensure that
the log file size is kept limited / constant in continuous operation:
logging_collector = on log_truncate_on_rotation = on log_rotation_age = 1d log_filename = '%A.log' # log file name pattern: creates a logfile with weekday name - will be overwritten after 7 days!
This must be set by the database administrator in the corresponding file:
<Project path>/db/wincc_oa/localdb/postgresql/<PostgreSQL Version>/pgdata/postgresql.conf
- Open the command shell on Windows or a terminal window on Linux.
- Change to the following WinCC OA product directory /bin/pgsql/bin. If an environment variable is set to this directory under Windows, this is not necessary.
- Execute the following psql
commands.
You must authenticate yourself (user = "etm" + your defined password for standard project creation or the default password for a "Legacy project"). If the command is executed successfully, the output is "<size/size> kB (100 %), 1/1 tablespace.pg_basebackup -D <db_target_backup_directory> [-U admin_user] [-h database_host] [-p database_port] -Ft -z -c spread -R -P
Note:The <db_target_backup_directory> must be empty. It is recommended to set up a "Date+Time" folder in the directory.CAUTION:The backup files are not encrypted. To prevent unauthorized access, ensure that the destination directory (db_target_backup_directory
), especially a remote directory, is secure. Use BitLocker (Windows) or other encryption programs to encrypt the backup files.
Restore the backup
- Use the database engineering panel to stop the database.
- Rename or remove the database configuration directory: <wincc oa project directory>/db/wincc_oa/localdb/postgresql/<PostgreSQL Version>/pgdata and create an empty new pgdata directory.
- Open the command shell on Windows or a terminal window on Linux.
- Change to the following WinCC OA product directory
<winccoa product
directory>/<version>/bin/pgsql/bin.
Note:Note that if an environment variable is set to this directory under Windows, this is not necessary. Note also that the target "database_directory" must be empty. You must first move or delete your old, corrupted database.
- Open the command prompt on Windows or your preferred terminal on Linux and
execute:
tar -xf <db_target_backup_directory>/base.tar.gz -C <wincc oa project directory>/db/wincc_oa/localdb/postgresql/<PostgreSQL Version>/pgdata tar -xf <db_target_backup_directory>/pg_wal.tar.gz -C <wincc oa project directory>/db/wincc_oa/localdb/postgresql/<PostgreSQL Version>/pgdata/pg_wal
- Use database engineering panel to start the server.
- Execute the following command to promote the database from standby to read-write
mode:
pg_ctl promote -D <database_directory>
If a database restore has become necessary and the NextGen Archiver has buffered the data from the failure, the buffers are automatically rewritten to the database after a new database connection and the buffers are resolved.
You can find all required commands in the readme file <winccoa product directory>/<version>data/NGA/PostgreSQL/sql>/readme.md