Skip to content

Commit

Permalink
update articles
Browse files Browse the repository at this point in the history
  • Loading branch information
mobeicanyue committed Mar 2, 2024
1 parent 27d7d75 commit c1ca7e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 0 additions & 1 deletion source/_posts/Compress-deploy-code-size.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
title: 压缩部署的代码
tags:
- hexo
- 部署
- 优化
abbrlink: a89b8953
date: 2023-12-28 02:51:41
Expand Down
29 changes: 17 additions & 12 deletions source/_posts/Using-postgresql-on-ArchLinux.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ abbrlink: d2adab3b
date: 2024-02-29 09:44:23
---

> 本文主要介绍如何在 ArchLinux 上安装和使用 `PostgreSQL`
>
> 我之前一直使用 `MySQL`,最近才接触 `PostgreSQL`。如果你也是 `PostgreSQL` 的新手,想必也会和我一样在安装使用的时候遇到一些问题(如安装了没有初始化数据库 启动失败等),所以我在这里记录一下我遇到的问题和解决方法。
{% note secondary %}
我之前一直使用 `MySQL`,最近才接触 `PostgreSQL`。如果你也是 `PostgreSQL` 的新手,想必也会和我一样在安装使用的时候遇到一些问题(如安装完没有初始化数据库 想启动服务却启动失败等),所以我在这里记录一下我遇到的问题和解决方法。

本文主要介绍如何在 ArchLinux 上安装和使用 `PostgreSQL`
{% endnote %}

1. 安装 `PostgreSQL`

## 1. 安装 `PostgreSQL`
```bash
sudo pacman -S postgresql
```
Expand All @@ -22,23 +24,25 @@ psql -V
```


2. 初始化数据库
## 2. 初始化数据库
`PostgreSQL``MySQL` 不同,它需要初始化数据库。
输入以下命令。
<br>
输入以下命令,来进入 `postgres` 用户的 shell `[postgres]$`
```bash
sudo -iu postgres
```
这时候你会进入到 `postgres` 用户的 shell `[postgres]$` 中,执行下面的命令
执行下面的命令来初始化数据库
```bash
initdb -D /var/lib/postgres/data
```
如果没有报错,可以退出 `postgres` shell。
```bash
exit
```
```


3. 启动 PostgreSQL 服务
## 3. 启动 PostgreSQL 服务
输入以下命令来启动 `PostgreSQL` 服务
```bash
sudo systemctl start postgresql
```
Expand All @@ -49,7 +53,7 @@ sudo systemctl status postgresql
如果显示 `active (running)` 就表示服务启动成功了。


4. 创建用户和数据库
## 4. 创建用户和数据库
PostgreSQL 还需要添加一个新的数据库用户。进入 `postgres` shell
```bash
sudo -iu postgres
Expand All @@ -59,15 +63,16 @@ sudo -iu postgres
createuser --interactive
```
输入要增加的角色名称,新的角色是否是超级用户。
<br>
提示:如果创建一个与 Linux 用户名相同的 PostgreSQL 角色/用户,就可以访问 PostgreSQL 数据库 shell,而无需指定用户登录(这非常方便)。

5. 创建数据库
## 5. 创建数据库
使用 createdb 命令,创建一个上述用户可以读写的新数据库。
```bash
createdb myDatabaseName
```

6. 登录数据库
## 6. 登录数据库
`postgres` shell 中,输入以下命令来登录数据库
```bash
psql
Expand Down

0 comments on commit c1ca7e1

Please sign in to comment.