config/database.yml under the adapter key.finance_tracker_development (for development).finance_tracker_test (for testing).finance_tracker role.Relevant Configurations (from config/database.yml):
development:
<<: *default
database: finance_tracker_development
username: finance_tracker
password:
test:
<<: *default
database: finance_tracker_test
username: finance_tracker
password:
Role Creation and Database Initialization
The finance_tracker role and databases were created as follows:
Check for Existing Roles:
psql postgres -c "\\du"
This lists all existing roles in the PostgreSQL server.
Create the Role:
createuser -s -r -d finance_tracker
s: Grants superuser privileges.r: Makes the role a login role (able to connect to databases).d: Allows the role to create databases.Create the Databases: Run the Rails command:
rails db:create
This initializes:
finance_tracker_developmentfinance_tracker_testVerify Role and Databases:
psql postgres -c "\\du"
psql -c "\\l"
Troubleshooting Common Issues
Issue: PostgreSQL Not Running
Error Message: psql: could not connect to server: No such file or directory.
Solution: Start the PostgreSQL server:
brew services start postgresql
Issue: Missing pg_config During gem install pg
Error Message: Can't find the 'libpq-fe.h header'.
Solution:
brew install libpq
brew link --overwrite libpq
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Issue: Permission Denied When Creating Databases
ERROR: permission denied to create database.s for superuser privileges:createuser -s -r -d finance_tracker