Skip to content

Commit

Permalink
deploy: c1ca7e1
Browse files Browse the repository at this point in the history
  • Loading branch information
mobeicanyue committed Mar 2, 2024
1 parent 693d4e1 commit d47d72f
Show file tree
Hide file tree
Showing 15 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link href="https://blog.ovvv.top/atom.xml" rel="self"/>

<link href="https://blog.ovvv.top/"/>
<updated>2024-03-02T05:12:22.000Z</updated>
<updated>2024-03-02T11:32:47.000Z</updated>
<id>https://blog.ovvv.top/</id>

<author>
Expand All @@ -21,7 +21,7 @@
<link href="https://blog.ovvv.top/posts/d2adab3b/"/>
<id>https://blog.ovvv.top/posts/d2adab3b/</id>
<published>2024-02-29T01:44:23.000Z</published>
<updated>2024-03-02T05:12:22.000Z</updated>
<updated>2024-03-02T11:32:47.000Z</updated>



Expand Down Expand Up @@ -504,7 +504,7 @@
<link href="https://blog.ovvv.top/posts/a89b8953/"/>
<id>https://blog.ovvv.top/posts/a89b8953/</id>
<published>2023-12-27T18:51:41.000Z</published>
<updated>2024-03-02T05:12:22.000Z</updated>
<updated>2024-03-02T11:32:47.000Z</updated>



Expand Down
Binary file modified atom.xml.br
Binary file not shown.
Binary file modified atom.xml.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html

Large diffs are not rendered by default.

Binary file modified index.html.br
Binary file not shown.
Binary file modified index.html.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion local-search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link href="/posts/d2adab3b/"/>
<url>/posts/d2adab3b/</url>

<content type="html"><![CDATA[<div class="note note-secondary"> <p>我之前一直使用 <code>MySQL</code>,最近才接触 <code>PostgreSQL</code>。如果你也是 <code>PostgreSQL</code> 的新手,想必也会和我一样在安装使用的时候遇到一些问题(如安装了没有初始化数据库 想启动服务却启动失败等),所以我在这里记录一下我遇到的问题和解决方法。</p><p>本文主要介绍如何在 ArchLinux 上安装和使用 <code>PostgreSQL</code>。</p> </div><h2 id="1-安装-PostgreSQL"><a href="#1-安装-PostgreSQL" class="headerlink" title="1. 安装 PostgreSQL"></a>1. 安装 <code>PostgreSQL</code></h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo pacman -S postgresql<br></code></pre></td></tr></table></figure><p>检查 <code>Postgresql</code> 版本</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">psql -V<br></code></pre></td></tr></table></figure><h2 id="2-初始化数据库"><a href="#2-初始化数据库" class="headerlink" title="2. 初始化数据库"></a>2. 初始化数据库</h2><p><code>PostgreSQL</code> 与 <code>MySQL</code> 不同,它需要初始化数据库。<br><br><br>输入以下命令,来进入 <code>postgres</code> 用户的 shell <code>[postgres]$</code> 中</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo -iu postgres<br></code></pre></td></tr></table></figure><p>执行下面的命令来初始化数据库</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">initdb -D /var/lib/postgres/data<br></code></pre></td></tr></table></figure><p>如果没有报错,可以退出 <code>postgres</code> shell。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">exit</span><br></code></pre></td></tr></table></figure><h2 id="3-启动-PostgreSQL-服务"><a href="#3-启动-PostgreSQL-服务" class="headerlink" title="3. 启动 PostgreSQL 服务"></a>3. 启动 PostgreSQL 服务</h2><p>输入以下命令来启动 <code>PostgreSQL</code> 服务</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo systemctl start postgresql<br></code></pre></td></tr></table></figure><p>确认服务是否启动成功</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo systemctl status postgresql<br></code></pre></td></tr></table></figure><p>如果显示 <code>active (running)</code> 就表示服务启动成功了。</p><h2 id="4-创建用户和数据库"><a href="#4-创建用户和数据库" class="headerlink" title="4. 创建用户和数据库"></a>4. 创建用户和数据库</h2><p>PostgreSQL 还需要添加一个新的数据库用户。进入 <code>postgres</code> shell</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo -iu postgres<br></code></pre></td></tr></table></figure><p>输入以下命令</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">createuser --interactive<br></code></pre></td></tr></table></figure><p>输入要增加的角色名称,新的角色是否是超级用户。<br><br><br>提示:如果创建一个与 Linux 用户名相同的 PostgreSQL 角色&#x2F;用户,就可以访问 PostgreSQL 数据库 shell,而无需指定用户登录(这非常方便)。</p><h2 id="5-创建数据库"><a href="#5-创建数据库" class="headerlink" title="5. 创建数据库"></a>5. 创建数据库</h2><p>使用 createdb 命令,创建一个上述用户可以读写的新数据库。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">createdb myDatabaseName<br></code></pre></td></tr></table></figure><h2 id="6-登录数据库"><a href="#6-登录数据库" class="headerlink" title="6. 登录数据库"></a>6. 登录数据库</h2><p>在 <code>postgres</code> shell 中,输入以下命令来登录数据库</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">psql<br></code></pre></td></tr></table></figure><p><code>postgres</code> shell 中,一些常用的命令:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash">\<span class="hljs-built_in">help</span> <span class="hljs-comment"># 列出所有命令</span><br>\l <span class="hljs-comment"># 列出所有数据库</span><br>\c database <span class="hljs-comment"># 连接到指定数据库</span><br>\<span class="hljs-built_in">du</span> <span class="hljs-comment"># 列出所有用户</span><br>\dt <span class="hljs-comment"># 列出当前数据库的所有表</span><br>\q <span class="hljs-comment"># 退出数据库</span><br></code></pre></td></tr></table></figure><br><p>参考文章:</p><section class="footnotes"><div class="footnote-list"><ol><li><span id="fn:1" class="footnote-text"><span><a href="https://wiki.archlinuxcn.org/wiki/PostgreSQL">https://wiki.archlinuxcn.org/wiki/PostgreSQL</a><a href="#fnref:1" rev="footnote" class="footnote-backref"> ↩</a></span></span></li><li><span id="fn:2" class="footnote-text"><span><a href="https://gist.github.com/NickMcSweeney/3444ce99209ee9bd9393ae6ab48599d8">https://gist.github.com/NickMcSweeney/3444ce99209ee9bd9393ae6ab48599d8</a><a href="#fnref:2" rev="footnote" class="footnote-backref"> ↩</a></span></span></li></ol></div></section>]]></content>
<content type="html"><![CDATA[<div class="note note-secondary"> <p>我之前一直使用 <code>MySQL</code>,最近才接触 <code>PostgreSQL</code>。如果你也是 <code>PostgreSQL</code> 的新手,想必也会和我一样在安装使用的时候遇到一些问题(如安装完没有初始化数据库 想启动服务却启动失败等),所以我在这里记录一下我遇到的问题和解决方法。</p><p>本文主要介绍如何在 ArchLinux 上安装和使用 <code>PostgreSQL</code>。</p> </div><h2 id="1-安装-PostgreSQL"><a href="#1-安装-PostgreSQL" class="headerlink" title="1. 安装 PostgreSQL"></a>1. 安装 <code>PostgreSQL</code></h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo pacman -S postgresql<br></code></pre></td></tr></table></figure><p>检查 <code>Postgresql</code> 版本</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">psql -V<br></code></pre></td></tr></table></figure><h2 id="2-初始化数据库"><a href="#2-初始化数据库" class="headerlink" title="2. 初始化数据库"></a>2. 初始化数据库</h2><p><code>PostgreSQL</code> 与 <code>MySQL</code> 不同,它需要初始化数据库。<br><br><br>输入以下命令,来进入 <code>postgres</code> 用户的 shell <code>[postgres]$</code> 中</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo -iu postgres<br></code></pre></td></tr></table></figure><p>执行下面的命令来初始化数据库</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">initdb -D /var/lib/postgres/data<br></code></pre></td></tr></table></figure><p>如果没有报错,可以退出 <code>postgres</code> shell。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">exit</span><br></code></pre></td></tr></table></figure><h2 id="3-启动-PostgreSQL-服务"><a href="#3-启动-PostgreSQL-服务" class="headerlink" title="3. 启动 PostgreSQL 服务"></a>3. 启动 PostgreSQL 服务</h2><p>输入以下命令来启动 <code>PostgreSQL</code> 服务</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo systemctl start postgresql<br></code></pre></td></tr></table></figure><p>确认服务是否启动成功</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo systemctl status postgresql<br></code></pre></td></tr></table></figure><p>如果显示 <code>active (running)</code> 就表示服务启动成功了。</p><h2 id="4-创建用户和数据库"><a href="#4-创建用户和数据库" class="headerlink" title="4. 创建用户和数据库"></a>4. 创建用户和数据库</h2><p>PostgreSQL 还需要添加一个新的数据库用户。进入 <code>postgres</code> shell</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo -iu postgres<br></code></pre></td></tr></table></figure><p>输入以下命令</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">createuser --interactive<br></code></pre></td></tr></table></figure><p>输入要增加的角色名称,新的角色是否是超级用户。<br><br><br>提示:如果创建一个与 Linux 用户名相同的 PostgreSQL 角色&#x2F;用户,就可以访问 PostgreSQL 数据库 shell,而无需指定用户登录(这非常方便)。</p><h2 id="5-创建数据库"><a href="#5-创建数据库" class="headerlink" title="5. 创建数据库"></a>5. 创建数据库</h2><p>使用 createdb 命令,创建一个上述用户可以读写的新数据库。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">createdb myDatabaseName<br></code></pre></td></tr></table></figure><h2 id="6-登录数据库"><a href="#6-登录数据库" class="headerlink" title="6. 登录数据库"></a>6. 登录数据库</h2><p>在 <code>postgres</code> shell 中,输入以下命令来登录数据库</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">psql<br></code></pre></td></tr></table></figure><p><code>postgres</code> shell 中,一些常用的命令:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash">\<span class="hljs-built_in">help</span> <span class="hljs-comment"># 列出所有命令</span><br>\l <span class="hljs-comment"># 列出所有数据库</span><br>\c database <span class="hljs-comment"># 连接到指定数据库</span><br>\<span class="hljs-built_in">du</span> <span class="hljs-comment"># 列出所有用户</span><br>\dt <span class="hljs-comment"># 列出当前数据库的所有表</span><br>\q <span class="hljs-comment"># 退出数据库</span><br></code></pre></td></tr></table></figure><br><p>参考文章:</p><section class="footnotes"><div class="footnote-list"><ol><li><span id="fn:1" class="footnote-text"><span><a href="https://wiki.archlinuxcn.org/wiki/PostgreSQL">https://wiki.archlinuxcn.org/wiki/PostgreSQL</a><a href="#fnref:1" rev="footnote" class="footnote-backref"> ↩</a></span></span></li><li><span id="fn:2" class="footnote-text"><span><a href="https://gist.github.com/NickMcSweeney/3444ce99209ee9bd9393ae6ab48599d8">https://gist.github.com/NickMcSweeney/3444ce99209ee9bd9393ae6ab48599d8</a><a href="#fnref:2" rev="footnote" class="footnote-backref"> ↩</a></span></span></li></ol></div></section>]]></content>



Expand Down
Binary file modified local-search.xml.br
Binary file not shown.
Binary file modified local-search.xml.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion posts/a89b8953/index.html

Large diffs are not rendered by default.

Binary file modified posts/a89b8953/index.html.br
Binary file not shown.
Binary file modified posts/a89b8953/index.html.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion posts/d2adab3b/index.html

Large diffs are not rendered by default.

Binary file modified posts/d2adab3b/index.html.br
Binary file not shown.
Binary file modified posts/d2adab3b/index.html.gz
Binary file not shown.

0 comments on commit d47d72f

Please sign in to comment.