Use the database on another host

Sometimes it’s necessary to place the database on another host, separate from StaffCop service and admin interface. The steps are the following:

  1. Create a database and a user staffcop with all the required permissions on the remote host.

  2. Update the PostgreSQL configuration file on the host:

  • open /etc/postgresql/11/main/postgresql.conf

  • locate the line starting with listen_addresses and uncomment it by removing the # symbol

  • add allowed IP addresses:

listen_addresses = '192.168.10.10, 192.168.10.112'

here, 192.168.10.10 is the Staffcop server address, while 192.168.10.112 is the admin workstation, such as for pgAdmin.

Note

Access for the user staffcop is granted via the command staffcop sql. Adding * grants access from any computer. You may want to use it only for debugging purposes.

  • once you’ve made these adjustments, restart the server:

service postgresql restart
  1. Then transfer the database to another host. Use for reference following guides in this article. On StaffCop Server, edit the following lines in /etc/staffcop/config by stating info of remote server:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'staffcop',
        'USER': 'staffcop',
        'PASSWORD': '1d6e8d9f8789400fed557937',
        'HOST': '192.168.1.222',
        'PORT': '5432',
    },
}

edit fields Host and password.

  1. In file /etc/postgresql/11/main/pg_hba.conf, add indent for StaffCop Server in a similar way:

host    staffcop        staffcop        192.168.0.0/22  trust

Note

The database path can be different, it depends on Postgresql version which you use.

  1. Check the server operability after transferring the database to another host.

To simplify configuring of the database on the remote host you can install StaffCop beforehand, it will automatically configure the database and after restoring backup from the main host it will be ready to receive data from the main server. The StaffCop service on the local host can be disabled:

systemctl disable taffcop

or stopped:

systemctl stop staffcop