当前位置: 首页 > 编程日记 > 正文

如何开始使用PostgreSQL

by Akul Tomar

通过Akul Tomar

如何开始使用PostgreSQL (How to get started with PostgreSQL)

PostgreSQL is an open source Relational Database Management System (RDBMS). In this article, I’ll provide an introduction to getting started with PostgreSQL. Here is what we’ll cover:

PostgreSQL是一个开源的关系数据库管理系统(RDBMS)。 在本文中,我将介绍PostgreSQL入门。 这是我们要介绍的内容:

  • Installation

    安装

  • Administration

    行政

  • Basic Database Operations

    基本数据库操作

安装 (Installation)

If you have homebrew installed on your system, you can run the command below on your terminal to quickly install PostgreSQL:

如果您的系统上安装了自制软件,则可以在终端上运行以下命令以快速安装PostgreSQL:

brew install postgresql

Others can download the latest version of PostgreSQL here and follow the installation steps.

其他人可以在这里下载最新版本的PostgreSQL并遵循安装步骤。

Once downloaded, to verify you’ve got PostgreSQL installed, run the following command to check your PostgreSQL version:

下载完成后,要验证是否已安装PostgreSQL,请运行以下命令以检查PostgreSQL版本:

postgres --version

行政 (Administration)

PostgreSQL can be administered from the command line using the psql utility, by running the command below:

可以使用以下命令通过psql实用工具从命令行管理PostgreSQL:

psql postgres

This should get your psql utility running. psql is PostgreSQL’s command line tool. While there are many third-party tools available for administering PostgreSQL databases, I haven’t felt the need to install any other tool yet. psql is pretty neat and works just fine.

这应该使您的psql实用程序运行。 psql是PostgreSQL命令行工具。 尽管有许多可用于管理PostgreSQL数据库的第三方工具,但我还没有必要安装任何其他工具。 psql非常简洁,可以正常工作。

To quit from the psql interface, you can type \q and you’re out.

要从psql界面退出,可以键入\q然后退出。

If you need help, type \help on your psql terminal. This will list all the available help options. You can type in \help [Command Name], in case you need help with a particular command. For example, typing in \help UPDATE from within psql will show you the syntax of the update option.

如果需要帮助, \help在psql终端上键入\help 。 这将列出所有可用的帮助选项。 如果需要有关特定命令的帮助,可以键入\help [Command Name] 。 例如,在psql输入\help UPDATE将显示更新选项的语法。

Description: update rows of a table[ WITH [ RECURSIVE ] with_query [, ...] ]UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]    SET { column_name = { expression | DEFAULT } |          ( column_name [, ...] ) = ( { expression | DEFAULT } [, ...] ) |          ( column_name [, ...] ) = ( sub-SELECT )        } [, ...]    [ FROM from_list ]    [ WHERE condition | WHERE CURRENT OF cursor_name ]    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

If you’re a beginner, you may still not understand. A quick Google search will provide you examples of its use or you can always search the official psql documentation which will provide many examples.

如果您是初学者,您可能仍然不明白。 快速的Google搜索将为您提供其用法示例,或者您始终可以搜索将提供许多示例的官方psql文档 。

When you first install PostgreSQL, there are a few common administrative tasks that you’ll frequently perform.

首次安装PostgreSQL时,您会经常执行一些常见的管理任务。

The first thing would be to check for existing users and databases. Run the command below to list all databases:

第一件事是检查现有的用户和数据库。 运行以下命令以列出所有数据库:

\list or \l

In the figure above, you can see three default databases and a superuser akultomar that get created when you install PostgreSQL.

在上图中,您可以看到在安装PostgreSQL时创建的三个默认数据库和一个超级用户akultomar

To list all users, use the \du command. The attributes of the user tell us that they’re a Superuser.

要列出所有用户,请使用\du命令。 用户的属性告诉我们他们是超级用户。

基本数据库操作 (Basic Database Operations)

To perform basic database operations, you use the Structured Query Language (commonly known as SQL).

要执行基本的数据库操作,请使用结构化查询语言(通常称为SQL)。

建立资料库 (Create a database)

To create a database, you use the create database command. In the example below, we’ll create a database named riskzone.

要创建数据库,请使用create database命令。 在下面的示例中,我们将创建一个名为riskzone的数据库。

If you forget the semicolon at the end, the = sign at the postgres prompt is replaced with a - as in the figure below. This is basically an indication that you need to terminate your query. You’ll understand it’s significance when you actually start writing longer queries. For now just put a semi-colon to complete the SQL statement and hit return.

如果忘记了最后的分号,则在postgres提示符下的=符号将替换为- ,如下图所示。 这基本上表明您需要终止查询。 当您真正开始编写更长的查询时,您将了解它的重要性。 现在只需要用分号来完成SQL语句并按回车即可。

创建一个用户 (Create a user)

To create a user, you use the create user command. In the example below, we’ll create a user named no_one.

要创建用户,请使用create user命令。 在下面的示例中,我们将创建一个名为no_one的用户。

When you create a user, the message shown is CREATE ROLE. Users are roles with login rights. I have used them interchangeably. You’ll also notice that the Attributes column is empty for the user no_one. This means that the user no_one has no administrative permissions. They can only read data and cannot create another user or database.

创建用户时,显示的消息是CREATE ROLE 。 用户是具有登录权限的角色。 我已经交替使用了它们。 您还会注意到,用户no_one的Attributes no_one空。 这意味着用户no_one没有管理权限。 他们只能读取数据,不能创建其他用户或数据库。

You can set a password for your user. To a set password for an existing user, you need use the \password command below:

您可以为用户设置密码。 要为现有用户设置密码,您需要使用以下\password命令:

postgres=#\password no_one

To set a password when a user is created, the command below can be used:

要在创建用户时设置密码,可以使用以下命令:

postgres=#create user no_two with login password 'qwerty';

删除用户或数据库 (Delete a user or database)

The drop command can be used to delete a database or user, as in the commands below.

可以使用drop命令删除数据库或用户,如以下命令所示。

drop database <database_name>drop user <user_name>
This command needs to be used very carefully. Things dropped don’t come back unless you have a backup in place.
需要非常小心地使用此命令。 除非您有备份,否则掉线的事情不会回来。

If we run the \du and \l that we learned about earlier to display the list of users and databases respectively, we can see that our newly created no_one user and riskzone database.

如果运行我们先前了解的\du\l分别显示用户和数据库列表,则可以看到我们新创建的no_one用户和riskzone数据库。

When you specify psql postgres (without a username), it logs into the postgres database using the default superuser (akultomar in my case). To log into a database using a specific user, you can use the command below:

当指定psql postgres (不带用户名)时,它将使用默认的超级用户(在我的情况下为akultomar )登录到postgres数据库。 要使用特定用户登录数据库,可以使用以下命令:

psql [database_name] [user_name]

Let’s login to the riskzone database with the no_one user. Hit \q to quit from the earlier postgres database and then run the command below to log into riskzone with the user no_one.

让我们用no_one用户登录到riskzone数据库。 命中\q从早期的Postgres数据库退出,然后运行下面的命令登录到riskzone与用户no_one

I hoped you like the short introduction to PostgreSQL. I’ll be writing another article to help you understand roles better. If you’re new to SQL, my advice would be to practice as much as you can. Get your hands dirty and create your own little tables and practice.

我希望您喜欢PostgreSQL简短介绍。 我将写另一篇文章,以帮助您更好地理解角色。 如果您不熟悉SQL,我的建议是尽可能多地练习。 弄脏双手,创建自己的小桌子并练习。

翻译自: https://www.freecodecamp.org/news/how-to-get-started-with-postgresql-9d3bc1dd1b11/

相关文章:

Java中数组常见的几种排序方法!

数组的定义&#xff1a; int[] arr new int[5];int[] arr1 {1,2,3,4,5};long[] arr2 new long[6];String[] strs new String[5];Person[] ps new Person[5]; 数组的操作&#xff1a; int[] arr {45, 34, 53, 43};Arrays.sort(arr);System.out.println(Arrays.toString(ar…

oracle 如何预估将要创建的索引的大小

一.1 oracle 如何预估将要创建的索引的大小 oracle 提供了2种可以预估将要创建的索引大小的办法&#xff1a; ① 利用包 Dbms_space.create_index_cost 直接得到 ② 利用11g新特性 Note raised when explain plan for create index 下边分别举例说明。 一.2 环境说明 [ora…

删除对象的某个属性

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 实现代码&#xff1a; var data {a:1,b:2,c:3}for(var item in data){if (item b) {delete data[item];} }console.log(data:, data) 打印结果&#xff1a; data: {a: 1, c: 3}

java 学到什么实习_我如何获得外展实习机会以及到目前为止所学到的知识

java 学到什么实习by Nguedia Adele由Nguedia Adele 我如何获得外展实习机会以及到目前为止所学到的知识 (How I got my Outreachy internship and what I’ve learned so far) I recently got accepted for an Outreachy internship, working with LibreHealth.我最近接受了与…

STM32F103C8开发板原理图和管脚图

转载于:https://www.cnblogs.com/libra13179/p/6894335.html

js实用数组方法

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 判断是否为数组 1. Array.isArray([]) 2. var arr[1,2] arr instanceof Array -->true arr instanceof String -->false map ---- 返回数组得出的结果 const filtered [1, 2,…

BasicModal - 简单易用的现代 Web App 弹窗

BasicModal 是为现代 Web 应用程序打造的弹窗系统。它包括所有你需要显示的信息&#xff0c;问题或接收用户的输入。这里的弹窗还可以链接起来&#xff0c;所以你可以很容易地建立一个预定义顺序的安装帮助或显示对话框。无效输入可以使用包含突出显示和处理功能。 在线演示 …

javascript选择器_如何通过选择正确JavaScript选择器来避免沮丧

javascript选择器选择器如何影响代码的快速指南 (A quick guide on how selectors affect your code) While working on a project, I ran into an issue in my code. I was attempting to define multiple HTML elements into a collection and then change those elements ba…

Asp.net中GridView使用详解(引)【转】

Asp.net中GridView使用详解(引) GridView无代码分页排序 GridView选中&#xff0c;编辑&#xff0c;取消&#xff0c;删除 GridView正反双向排序 GridView和下拉菜单DropDownList结合 GridView和CheckBox结合 鼠标移到GridView某一行时改变该行的背景色方法一 鼠标移到GridView…

《任正非:我若贪生怕死,何来让你们英勇奋斗》

非常高兴尼泊尔代表处的进步&#xff0c;你们的一个历史项目概算亏损&#xff0c;从大前年亏损2.7亿美金&#xff0c;到前年亏损3000万美金&#xff0c;到去年盈利2140万美金。在喜马拉雅南麓一路爬坡&#xff0c;辛苦了。听说去年你们都涨了工资&#xff0c;我十分高兴。巴西代…

个人使用微信支付

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 首先在PAYJS申请到商户号和密钥&#xff0c; 然后实现源码如下&#xff1a; <!DOCTYPE html> <html lang"zh"><head><meta charset"UTF-8"><title>…

构建node.js基础镜像_我如何使用Node.js构建工作抓取网络应用

构建node.js基础镜像by Oyetoke Tobi Emmanuel由Oyetoke Tobi Emmanuel 我如何使用Node.js构建工作抓取网络应用 (How I built a job scraping web app using Node.js) Scraping jobs from the web has now become easier thanks to Indreed.现在&#xff0c;借助Indreed&…

Robotium测试报告的生成方法(上)

7.1 使用junit-report生成报告 这个是参考网上的&#xff1a;http://www.xuebuyuan.com/2148574.html&#xff0c;经我个人验证是可行的方法&#xff0c;网上写的挺详细的&#xff0c;不过有些不太清楚明白的地方&#xff0c;鉴于网上说的有点迷茫&#xff0c;所以下面我再细化…

Python之向日志输出中添加上下文信息

除了传递给日志记录函数的参数&#xff08;如msg&#xff09;外&#xff0c;有时候我们还想在日志输出中包含一些额外的上下文信息。比如&#xff0c;在一个网络应用中&#xff0c;可能希望在日志中记录客户端的特定信息&#xff0c;如&#xff1a;远程客户端的IP地址和用户名。…

小程序点击图片自动播放视频,停止上一个视频播放

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 通过列表的点击事件自动播放列表对应的视频&#xff0c;同时停止上一个视频的播放 源码&#xff1a; <view><view classvv wx:for{{vedio_data}} wx:key><view classblock stylemargin…

hitchhiker部署_Hitchhiker的React Router v4指南:无限远的递归路径!

hitchhiker部署Welcome to the third part of the Hitchhiker’s Guide to React Router v4. In this article we’re going to focus on recursive paths. If you’ve missed the first two parts, you can find part 1 here and part 2 here.欢迎阅读《 Hitchhiker React Rou…

smbpasswd 和 pdbedit 的区别

smbpasswd 和 pdbedit 的区别 以前我们在windows上共享文件的话&#xff0c;只需右击要共享的文件夹然后选择共享相关的选项设置即可。然而如何实现windows和linux的文件共享呢&#xff1f;这就涉及到了samba服务了&#xff0c;这个软件配置起来也不难&#xff0c;使用也非常简…

DB天气app冲刺二阶段第十一天(完结)

今天最后一天冲刺了&#xff0c;明天就不再冲刺了。。已经把所有的技术的问题还有设计的问题都弄好了吧应该说 至少目前来说是的。因为有的实现不了的或者需要耗费时间的已经果断舍弃了&#xff0c;然后需要完善的也都基本完善了。 现在还需要做的就是素材的收集整理。需要抽半…

如何超越console.log并充分利用浏览器的调试控制台

by Gilad Dayagi通过吉拉德达亚吉 The console object is a very useful feature of browsers that has been around for many years. It provides access to the browser’s debugging console.Most web developers know how to print messages to the console using console…

区域设置 ID (LCID) 表, 及获取方法

区域设置 ID (LCID) 表, 及获取方法 中国的区域设置 ID 是 2052, 如果经常打开微软软件的安装目录应该经常见到.获取很简单, 有现成的 API 函数: GetThreadLocale.beginShowMessage(IntToStr(GetThreadLocale)); //2052 end; 区域设置 ID (LCID) 表区域设置描述简写十六进制值十…

E201700525-hm

skeleton n. 骨骼; &#xff08;建筑物等的&#xff09; 骨架; 梗概; 骨瘦如柴的人&#xff08;或动物&#xff09;;adj. 骨骼的; 骨瘦如柴的; 概略的; 基本的; cloud n. 云; 云状物; invoke vt. 乞灵&#xff0c;祈求; 提出或授引…以支持或证明; 召鬼; 借助;render …

php不显示报错

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 error_reporting(E_ALL & ~E_NOTICE);

致谢 开源开发者的贡献_对开源做出的贡献如何使我成为更好的开发人员,以及如何做到这一点...

致谢 开源开发者的贡献by Luciano Strika通过卢西亚诺斯特里卡(Luciano Strika) 对开源做出的贡献如何使我成为更好的开发人员&#xff0c;以及如何做到这一点 (How contributing to open source made me a better developer — and how you can do it, too) So you’ve been …

欲精一行,必先通十行

将前端开发和服务器端开发做一个比较&#xff0c;前端开发没有服务器端开发“深”&#xff0c;服务器端开发没有前端开发“广”。经常听到做前端的同行抱怨需要学的东西太 多&#xff0c;东学一点西学一点&#xff0c;什么都会&#xff0c;但也什么都不精。很直接的结果就是沦为…

LeetCode 228: Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 代码要求对数组中的元素进行分段。 首先给出字符串格式化函数&#xff0c;假设be…

JQ+ajax 提交表单不跳转页面

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 代码 <div class"apply_box"><h1>合作申请</h1><div class"apply_l"><input type"text" maxlength"20" id"name" name&q…

node.js是开源的吗_为开源做贡献并不难:我为Node.js项目做贡献的旅程

node.js是开源的吗As a developer, you should consider contributing to open source software. Many of your potential employers will look favorably on these contributions.作为开发人员&#xff0c;您应该考虑为开源软件做贡献。 您的许多潜在雇主将对这些供款看好。 …

超级简单的jquery轮播图demo

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title>轮播图demo</title><script type"text/javascript" src"js/jquery-3.2.1.slim.js" ></script><link rel"stylesheet" …

Mysql 操作技巧

复制表结构 表数据Mysql> create tables t2 like t1;Mysql> insert into t2 select * from t1; mysql 索引a、Alert Table 用来创建普通索引、Unique 唯一索引 (当前列数值不可重复) 或 Primary Key 主键索引Mysql> alter table table_name add index index_name(col…

JS实现复制到剪切板效果

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 代码&#xff1a; <!DOCTYPE html> <html lang"en"><head><meta http-equiv"Content-Type" content"text/html; charsetutf-8" /><meta cha…