-
Notifications
You must be signed in to change notification settings - Fork 0
Postgres
E. Lynette Rayle edited this page Mar 2, 2022
·
4 revisions
Reference: http://blog.jasonmeridth.com/posts/postgresql-command-line-cheat-sheet/
See SQL Queries for query examples
$ psql postgres
postgres=#
Exit command line
\q # backslash q
\l # backslash l
\c a_db_name
\du
\dt
\d a_table_name
CREATE ROLE new_role_name WITH LOGIN ENCRYPTED PASSWORD 'password1' CREATEDB;
CREATE DATABASE new_database_name WITH OWNER a_role_name ENCODING 'UTF8';
DROP DATABASE a_db_name;
Ref: https://www.postgresql.org/docs/9.1/static/sql-grant.html
GRANT ALL PRIVILEGES ON DATABASE a_db_name TO a_role_name;
Ref: https://www.postgresql.org/docs/9.1/static/sql-alterdatabase.html
ALTER DATABASE a_db_name OWNER TO new_owner;
ALTER USER a_role_name WITH SUPERUSER;
Reference: https://launchschool.com/blog/how-to-install-postgresql-on-a-mac
\c a_db_name
brew install postgresql
\c a_db_name
Prereq: Install Homebrew services (one time only)
brew tap homebrew/services
Running postgres service
brew services start postgresql
brew services restart postgresql
brew services stop postgresql
NOTE: Restarts automatically after computer restart.
\c a_db_name
psql -V
Reference: https://launchschool.com/blog/how-to-install-postgresql-on-a-mac
rails new -d postgresql
OR
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
OR
edit Gemfile and add gem
gem 'pg', '~> 0.18'
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: myapp_dev
username: your_username_for_postgres
password: your_password_for_postgres
test:
<<: *default
database: myapp_test
username: your_test_username_for_postgres
password: your_test_password_for_postgres