Install postgresql packages
- postgresql11.x86_64
- postgresql11-devel.x86_64
- postgresql11-libs.x86_64
- postgresql11-server.x86_64
# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# yum install postgresql11 postgresql11-devel postgresql11-libs postgresql11-server
Set PATH
# echo 'export PATH=/usr/pgsql-11/bin:$PATH' >> /home/<your user>/.bash_profile
# echo 'export PATH=/usr/pgsql-11/bin:$PATH' >> $HOME/.bash_profile
# export PATH=/usr/pgsql-11/bin:$PATH
Initialize database
# postgresql-11-setup initdb
Edit /var/lib/pgsql/11/data/pg_hba.conf
# sed -i -E '/^#/!s/^/#/g' /var/lib/pgsql/11/data/pg_hba.conf
# echo "local all postgres trust" >> /var/lib/pgsql/11/data/pg_hba.conf
# echo "host all postgres 127.0.0.1/32 trust" >> /var/lib/pgsql/11/data/pg_hba.conf
Start service
# systemctl enable postgresql-11.service
# systemctl start postgresql-11.service
Create rails app
# su - <your user>
$ rails new <app name> --database=postgresql
Edit config/database.yml
Add host, port, and username:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: 127.0.0.1
port: 5432
username: postgres
Comment out username and password
production:
<<: *default
database: blog_production
#username: blog
#password: <%= ENV['BLOG_DATABASE_PASSWORD'] %>
Setup db
$ bin/rails db:setup
$ bin/rails db:migrate
Start server
$ bin/rails server -b 0.0.0.0