This article describes how to relocate a PostgreSQL database to a different drive while preserving the ability to access it through the Web Reports for historical reporting. In this example, an old archive database is moved to the E: drive using a PostgreSQL tablespace.
Prerequisites
1- The database being moved must be disconnected from all EventSentry instances before starting; the relocation will fail if the database is still in use.
2- Ensure you have the postgres and eventsentry_web user passwords.
Step 1: Prepare the Destination Folder
PostgreSQL requires an empty folder to initialize a tablespace.
1- Create a new, empty folder on the target drive (e.g., E:\ES_Archive).
2- Right-click the folder and select Properties -> Security.
3- Confirm that the account running the EventSentry Database v14 service (NetworkService by default) has Full Control of this folder.
Note: Incorrect folder permissions are the most common cause of failure in this procedure. If the tablespace creation in Step 2 fails with a permissions error, revisit this step before proceeding.
Step 2: Create the Tablespace in PostgreSQL
Open pgAdmin, connect to your PostgreSQL instance, and execute the following SQL statement: CREATE TABLESPACE old_db_space LOCATION 'E:/ES_Archive';
Note the use of forward slashes (/) in the path. You can substitute old_db_space with any tablespace name that fits your naming convention.
Step 3: Move the Existing Database to the New Tablespace
Run the following SQL command, replacing your_database_name with the actual name of the archive database:ALTER DATABASE your_database_name SET TABLESPACE old_db_space;
PostgreSQL will physically relocate the database files to the new tablespace location on the E:\ drive. Depending on the size of the database, this operation may take several minutes.
Important: The database must have zero active connections while this command runs. If you encounter a "database is being accessed by other users" error:
- Verify that you are not actively connected to the database you want to move.
- Try to stop all EventSentry services, leaving only the EventSentry Database V14 service running.
Step 4: Verify the Relocation
Confirm the move was successful by running:SELECT datname, pg_tablespace.spcname
FROM pg_database
JOIN pg_tablespace ON pg_database.dattablespace = pg_tablespace.oid
WHERE datname = 'your_database_name';
The result should show the database associated with old_db_space. You can also verify that the database files now exist under E:\ES_Archive or the directory you configured in the previous steps.
Step 5: Connect the Archive Database to Web Reports
Once the database has been relocated:
1- In Web Reports, go to Settings > Profile Editor.
2- Select New Profile and name it.
3- Enter the connection settings for your old database (the postgres and eventsentry_web users), then Test Connection.
4- Save (Submit) the profile and confirm that historical data is accessible through the Web Reports.
The archive database is now available for historical access without occupying space on the original drive. You can now switch between databases using the profile dropdown menu in the upper-left corner of the Web Reports.
Related Articles
How to Create a New Database and Archive the Old Database
How to Set Up a Parallel Archive Database Using the Archive Feature