Initialize Database

Prerequisites

  • PostgreSQL Client

    Ensure the psql command-line tool is installed and available in your system’s PATH.

  • Zip Utility

    Ensure you have a tool to extract .zip files (e.g., unzip).

  • Permissions

    The database user must have sufficient privileges to: - Connect to the PostgreSQL server. - Create a new database (if it does not exist). - Execute the SQL scripts.

Steps to Run the Script

  1. Locate the db-init.zip file.
  2. Extract the contents to a directory of your choice. This will create a db-init directory containing the script and SQL files.
    unzip db-init.zip -d db-init
    
  3. Navigate to the directory where the files were extracted.
    cd db-init
    
  4. Ensure the run_scripts.sh script is executable.
    chmod +x run_scripts.sh
    
  5. Execute the script.
    ./run_scripts.sh
    
  6. When prompted, provide the following details:
    • Database Name — Name of the database to connect to or create.
    • Database Host — Hostname or IP address of the PostgreSQL server.
    • Database User — Username to connect to the PostgreSQL server. The user should have access to create user,roles,schemas,database.
    • Database Password — Password for the specified user.

Example Execution

$ ./run_scripts.sh
Enter database name: testautomationdb
Enter database host: 10.101.2.101
Enter database user: postgres
Enter database password: ********
Testing connectivity to the database server...
Checking if the database 'testautomationdb' exists...
Database 'testautomationdb' does not exist. Creating it...
Database 'testautomationdb' created successfully.
Running SQL scripts...
SQL scripts executed successfully.

Considerations

Database

  • This script is intended for PostgreSQL databases only.
  • Use strong passwords for database users.
  • Review the TA_PREREQ.sql and FW_PREREQ.sql files to ensure requirements are met before execution.

Dynamic Paths

  • The script dynamically determines its directory and uses it to locate the SQL files.
  • Ensure the TA_PREREQ.sql and FW_PREREQ.sql files are in the same directory as the script after extraction.

Database Privileges

  • The user specified in the script must have the CREATE DATABASE privilege to create a new database, if it does not exist.

Error Handling

  • If the script fails to connect to the database server, verify the host, username, and password.
  • If the database creation fails, ensure the user has sufficient privileges.

Troubleshooting

Connection Issues

  • Ensure the PostgreSQL server is running and accessible from the host where the script is executed.
  • Verify that the firewall or network settings allow connections to the PostgreSQL server on port 5432.

Permission Errors

  • Ensure the database user has the necessary privileges to create databases and execute the SQL scripts.

File Not Found

  • If the script reports missing SQL files, ensure the db-init.zip file was extracted correctly and all files are in the same directory.