markdown PostgreSQL的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown PostgreSQL的相关的知识,希望对你有一定的参考价值。

## Installing PostgreSQL
* ensure that homebrew is installed: `brew install postgres`
* fix errors if any (look below)
* `initdb /usr/local/var/postgres` for **first** time!!!!!!
* `pg_ctl -D /usr/local/var/postgres start` needs to be run in a terminal
* add to `Gemfile`: `gem 'pg'`
* `bundle install`

## Setting up PSQL
* Need to enter postgres, enter in terminal: `psql postgres`
* Next, create a user (or role as postgres calls it): 
`create role myapp with createdb login password 'password';`
* List all roles: `\du`
* List all databases: `\l`
* List all tables in the database: `\d`
* Connect to another db: `\c dbname`
* Describe (show) table: `\d dbname`
* Quit: `\q`


## Connecting pgAdmin to Postgres DB
* Open pgadmin
* `File` > `Add Server` > `New Server Registration`
* Set `Host` to `localhost` and `Port` to `5432` (default port unless set otherwise)
* Double click on the server and enter password when prompted


## Creating Your Rails App for Postgres
* `rails new myapp --database=postgresql`
* Using rails 4.2.5, use `pg gem 'pg', '0.17.0'` in `Gemfile`
* Keep the name of the app the same as the name of the psql user (can be changed)

## Configuring the Rails App
* In `config/database.yml`, consists of 3 different environments and thus 3 different db's!
* Ensure that the `username` and `password` are the ones that were used when creating the user!!!

```ruby
development:
  adapter: postgresql
  encoding: unicode
  database: my_app_development
  pool: 5
  username: myapp
  password: password
  
  
test:
  adapter: postgresql
  encoding: unicode
  database: my_app_test
  pool: 5
  username: myapp
  password: password
```

## `bundle exec rake db:setup`
* run the command above to _**create**_ the different database's!

## Other tools
* May want to install **pgAdmin** as a GUI to see your databases!

## Errors Occuring with Installation
* If you encounter:

```
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/man/man3/SPI_connect.3
/usr/local/share/man/man3 is not writable.
```

* Try this:

```
sudo chown -R `whoami` /usr/local/share/man/
# enter password
brew link postgresql
# should say: Linking /usr/local/Cellar/postgresql/10.3... 377 symlinks created
```

  

以上是关于markdown PostgreSQL的的主要内容,如果未能解决你的问题,请参考以下文章

markdown PostgreSQL的

markdown PostgreSQL命令行备忘单

markdown Postgresql杀挂查询

markdown 更改postgreSQL用户密码

markdown 更改postgreSQL用户密码

markdown PostgreSQL索引提示