1.安装配置流程

  1. 安装

Mac平台:

brew update

brew install postgresql

Centos平台:

Install the repository RPM:

sudo yum install -y
https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Install PostgreSQL:

sudo yum install -y postgresql13-server

Optionally initialize the database and enable automatic start:

sudo /usr/pgsql-13/bin/postgresql-13-setup initdb

sudo systemctl enable postgresql-13

sudo systemctl start postgresql-13

Next, check your PostgreSQL version:

postgres –version

postgres (PostgreSQL) 12.2

The command line results will show the version you have installed on
your local machine. I recommed using the latest version of libraries and
software whenever possible to avoid compatibility issues with
client-side applications.

二、HOW TO CREATE A PHYSICAL POSTGRESQL DATABASE

Now you can initialize the physical space on your hard-disk to allocate
databases. To do this, create a default postgres database on the
command line in case it didn’t happen automatically:

initdb /usr/local/var/postgres

如果已经存在文件夹postgres,则可以跳过这一步。

You will see the error message: “initdb: directory
“/usr/local/var/postgres” exists but is not empty”
 if the database
was already created when you installed PostgreSQL. It means the folder
where you are attempting to create a physical place for the database
already has one. Either way, next you can move on to the next step.

When you connect to this physical database later, you will see
an [actual
database]{.ul}
 which
is called “postgres” as well. The postgres database is meant to be the
default database for any third-party tools that you are using in
combination with PostgreSQL. These tools attempt to make the default
connection to this default database, so you shouldn’t delete it.

三、 使用PoStgres用户进行操作

Use the operating system user postgres to create your database - as
long as you haven’t set up a database role with the necessary
privileges that corresponds to your operating system user of the same
name (h9uest in your case):

sudo -u postgres -i

登录之后创建.bash_profile文件,并将pg的指令目录加入到PATH中:

export PG_ROOT=”/usr/pgsql-13”

export PATH=”$PG_ROOT/bin:$PATH”

四、 HOW TO START/STOP A POSTGRESQL DATABASE

Let’s see next how you can interact with the actual database. Manually
start and stop your Postgres database server with the following
commands:

pg_ctl -D /usr/local/var/postgres start

pg_ctl -D /usr/local/var/postgres stop

The terminal will confirm these operations with “server
started”
 and “server stopped” feedback. You could also implement a
script to start the server each time you boot up the machine, but I like
to have control over when to start and stop my database server to avoid
complications.

在CentOS上可以:

systemctl start postgresql

systemctl stop postgresql


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!