COMP9315-install and setup postgresql15.6

学习需要安装一个最新的postgresql版本,参考最新的链接

COMP9315 24T1 - Prac Exercise 01 (unsw.edu.au)

cgi.cse.unsw.edu.au/~cs9315/24T1/pracs/p01/beer.dump

PostgreSQL: File Browser

内容待一步一步跟着链接文档操作:

Prac Exercise 01
Setting up your PostgreSQL Server
Aims 
This exercise aims to get you to: 
• set up your directories on a file system 
• install a PostgreSQL database server  
You ought to get it done by the middle of Week 2.
Notation: In the examples below, 
we have used the $ sign to represent the prompt from the Unix/Linux shell. 
The actual prompt may look quite different on your computer (e.g. it may contain the computer's hostname, or your username, or the current directory name). 
In the example interactions, all of the things that the computer displays are in this font. 
The commands that you are supposed to type are in this bold font. 
Comments in the examples are introduced by '...' and are written in this grey font; 
comments do not appear on the computer screen, they simply aim to explain what is happening. 
Whenever we use the word edit, this means that you should use your favourite text editor (e.g. vi, emacs, gedit, etc.) 
Finally, some commands use YOU as a placeholder for your CSE username (which is usually your zid). 
This is the same as the $USER environment variable in Linux.

Background
PostgreSQL has three major components:
• the source code (and the compiled *.o files) (approx 200MB)
• the installed executables (like pg_ctl and psql) (approx 20MB)
• the data (including configuration files and databases) (at least 35MB)
You will not be able to fit the above components under your CSE home directory (insufficient disk quota)
The practical work for the assignments can be carried out on a special CSE server called vxdb. 
You run your own PostgreSQL server on this machine and are effectively the database administrator of this server. 
This machine has been configured to run large numbers** of PostgreSQL servers.
** Note: "large numbers" is around 300. If you leave your work to the last minute, 
and find 400 other students all trying to run PostgreSQL on vxdb, performance will be sub-optimal次优. 
Of course, you can avoid this potential bottleneck by installing and running PostgreSQL on your home machine.
自己搞台机器运行pg

You must put your PostgreSQL source code, installed executables and data under the /localstorage/$USER directory on vxdb. 
You must run the server process on vxdb; do not run your PostgreSQL server process on any other CSE machines; 
if you do, your PostgreSQL server will most likely be terminated automatically not long after it starts.

If you're doing all of this work on a laptop or desktop at home, then you can configure things however you like. 
You will still need folders for the same three components (source code, executables, and data), but you can place them wherever you like. 
PostgreSQL doesn't require any special privileges to run (at least on Unix-based systems like Linux and Mac OS X), 
so you do not need to create a special privileged PostgreSQL user; you can run the server as yourself.
没有特权要求

Reminder提醒: You should always test your work on vxdb before you submit assignments, 
since that's where we'll be running our tests to award your marks.

Getting started on vxdb--登录vxdb服务器
You may have a /localstorage/$USER directory on vxdb already (e.g. from a previous database course). 
If so, you can skip this section; but you might want to clean out any pgsql directory before you continue.
You can log into vxdb from a command-line (shell) window on any CSE machine (including vlab) via the command
$ ssh nw-syd-vxdb.cse.unsw.edu.au
If you're doing this exercise from home, you can use any ssh client, but you'll need to refer to nw-syd-vxdb.cse as d.cse:
$ ssh YourZID@d.cse.unsw.edu.au
You can check whether you're actually logged in to vxdb by using the command:
$ hostname
nw-syd-vxdb
Your home directory at CSE is directly accessible from vxdb.
The first time you log in to vxdb, it automatically creates a directory under /localstorage to hold your databases:
$ ls -al /localstorage/$USER
This directory is initially empty, but we're about to put the files for a PostgreSQL server into it.

Setting up your PostgreSQL Server
Reminder: If you are working from CSE make sure you are ssh'd on into vxdb. 
The times below are approximate大概; they could double or triple 三重 depending on your environment.

Quick summary (for experts only):专家级
Non-experts should go straight to the detailed instructions below.

$ cd /localstorage/$USER
$ tar xfj /web/cs9315/24T1/postgresql/postgresql-15.6.tar.bz2
$ cd postgresql-15.6
$ ./configure --prefix=/localstorage/$USER/pgsql
$ make
$ make install
$ cp  /web/cs9315/24T1/postgresql/env  /localstorage/$USER/env
$ source /localstorage/$USER/env
$ which initdb
$ initdb
$ ls $PGDATA
$ edit $PGDATA/postgresql.conf
$ which pg_ctl
$ pg_ctl start -l $PGDATA/log
$ psql -l
$ pg_ctl stop

Installation Details (for non-experts):非专家,给出详细步骤
步骤1:Setting up directories 设置目录
The first step is to make sure that the directory /localstorage/$USER exists. You can check this via the command:
$ ls -l /localstorage/$USER
If the above command says something like "No such file or directory", then you should create it using the instructions above.
Once you have a directory on the /localstorage filesystem, the next step is to place a copy of the PostgreSQL source code under this directory. The following commands will do this:
$ cd /localstorage/$USER
$ tar xfj /web/cs9315/24T1/postgresql/postgresql-15.6.tar.bz2
This creates a subdirectory called postgresql-15.6 under your /localstorage/$USER directory and unpacks all of the source code there. 
This produces no output and will take a few moments to complete. 
If you want to watch as tar unpacks the files, use xvfj instead of xfj as the first argument to tar.

步骤2:Initial compilation 初始化编译
Once you've unpacked the source code, you should change into the newly created postgresql-15.6 directory and configure the system so that it uses the directory /localstorage/$USER/pgsql to hold the executables for your PostgreSQL server. (Note that /localstorage/$USER/pgsql does not exist yet; it will be created in the make install step). 
The following commands will do the source code configuration:
$ cd /localstorage/$USER/postgresql-15.6
$ ./configure --prefix=/localstorage/$USER/pgsql
The configure command will print lots of messages about checking for various libraries/modules/etc. 
This process will take a minute, and should produce no errors.

configure: error: readline library not found

sudo apt install libreadline-dev
yum -y install -y readline-devel

yum install -y readline-devel
 

After configuring the source code, the next step is to build all of the programs. 
Stay in the postgresql-15.6 directory and then run the command:
$ make
This compiles all of the PostgreSQL source code, and takes around 4-5 minutes (depending on the load on vxdb). 
It will produce lots of output, but should compile everything OK. If anything goes wrong, the make process will stop partway through with an obvious error message.

步骤3:Installing executables 安装
Once the PostgreSQL programs are compiled, you need to install them. The following command does this:
$ make install 
This creates the directory /localstorage/$USER/pgsql, and copies all of the executables (such as pg_ctl and psql) under that directory. 
It will take a minute to do this, and will produce quite a bit of output while it's doing it.

步骤4:Data directories 数据目录
You're not finished yet, however, since PostgreSQL has no directory in which to store all of its data. 
You will install the data directories under /localstorage/$USER/pgsqlBefore doing anything with the database, however, you need to ensure that your Unix environment is set up correctly. 
We have written a small script called env that will do this. In this set up stage, you should copy this script to your /localstorage directory:
$ cp  /web/cs9315/24T1/postgresql/env  /localstorage/$USER/env
The env script contains the following:

export PGDATA=/localstorage/$USER/pgsql/data
export PGHOST=$PGDATA
export LD_LIBRARY_PATH=/localstorage/$USER/pgsql/libexport PATH=/localstorage/$USER/pgsql/bin:$PATHalias p0="pg_ctl stop"
alias p1="pg_ctl -l $PGDATA/log start"

This script sets up a number of environment variables. The critical ones are:
PGDATA which tells the PostgreSQL server where it's data directories are located
PGHOST which tells PostgreSQL clients where are the socket files to connect to the server
Note that in the discussion below, we will use the string YOUR_PGDATA to refer to that value that you assigned to PGDATA in your env file and which has been set by source'ing the env file in your shell.

步骤5:Initialising data directories and running server 初始化数据并运行
Once you have a copy of the env script and have set the values appropriately, 
you need to invoke it in every shell window where you plan to interact with the database. 
You can do this by explicitly running the following command in each window:
$ source /localstorage/$USER/env
If that gets tedious, you might consider adding the above command to your shell's startup script (e.g., ~/.bash_profile).
Once you've set up the environment, check that it's ok via the following commands:
$ echo $PGDATA
YOUR_PGDATA ... i.e. whatever value you set it to ...
$ which initdb
/localstorage/YOU/pgsql/bin/initdb
$ which pg_ctl
/localstorage/YOU/pgsql/bin/pg_ctl
If the system gives you different path names to the above, then your environment is not yet set up properly. Are you sure that you source'd your env file?

If all of the above went as expected, you are now ready to create the data directories and run the server. You can do this via the command:
$ initdb
... some output eventually finishing with something like ...
Success. You can now start the database server using:
    pg_ctl -D YOUR_PGDATA -l logfile start
If you look at your data directory now, you should see something like:
$ ls $PGDATA
PG_VERSION    pg_hba.conf 

然后还要修改配置文件
You shouldn't start the server straight away, however, since there's one more bit of configuration needed. 
You need to edit the postgresql.conf file in the $PGDATA directory and change the values of the following:
4条修改:
• change the value of the listen_addresses parameter to '': this means that only Unix-domain sockets can be used to connect to the server (saving you fighting over TCP ports);
• reduce the value of max_connections from 100 to 10: this reduces the resources tied up by the server to support those connections potentially occurring; and 
• set the value of the unix_socket_directories parameter to the full path of your $PGDATA directory; make sure to input the literal path instead of using $USER (e.g. /localstorage/z5555555/pgsql/data): this specifies where PostgreSQL keeps its connection sockets, and should be the same as your $PGDATA so psql and other clients can connect; and
• set the value of max_wal_senders to e.g. 4 (or any value less than whatever value you use for max_connections) Once you're done, the "connections and authentications" part of your modified postgresql.conf file should look like (with the changes highlighted in red):

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------# - Connection Settings -listen_addresses = ''                   # what IP address(es) to listen on;# comma-separated list of addresses;# defaults to 'localhost'; use '*' for all# (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 10                    # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
unix_socket_directories = 'YOUR_PGDATA' # comma-separated list of directories# (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation# (change requires restart)
....
max_wal_senders = 4

Note that it doesn't matter that the file says port = 5432
this value will be overridden by whatever you set your PGPORT environment variable to.
Note also that the 5432 also doesn't matter because the # at the start of the line means that it's a comment. In the case of the lines that you are supposed to change, make sure that you remove the # from the start of those lines.

Everything is now ready to start your PostgreSQL server, which you can do via the command: 万事俱备,可以启动了
$ pg_ctl start -l $PGDATA/log

You may have noticed that we provided you with shorthand to start and stop the server in the env file. The command p1 starts the server and p0 stops it.
简化命令

Note that PostgreSQL says "server starting", whereas it should probably say "attempting to start server".
A quick way to check whether the server is working is to run the command:
$ psql -l
It is possible that the server may not start correctly. If the server does not appear to have started, you can check why by looking at the tail of the server log:
$ tail -20 $PGDATA/log
... information about what happened at server start-time ...

错误定位
Note that you'll get error messages about not being able to run the statistics collector, 
and a warning that autovacuum was not started. These are not an issue at this stage.
If the server is running correctly, the psql -l will give you a list of databases like the above. 
If the server is not running, you'll get a message something like:
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "YOUR_PGDATA/.s.PGSQL.5432"?
If this happens, you should check the log file to find out what went wrong. (Other things to check in case of problems are described below).

Assuming that the server is running ok, you can now use it to create and manipulate databases (see the example below). 
Once you've finished your session using PostgreSQL, you need to stop the server.
$ pg_ctl stop
waiting for server to shut down.... done    

If you still have a process that's using the database (e.g. a psql process in another window), 
then the server won't be able to shut down. 
You'll need to quit all of the processes that are accessing the database before the above command will work.

步骤6:A Typical session with PostgreSQL
source /localstorage/$USER/env
p1
... hopefully concluding with the message ...
server started
psql -l
... hopefully giving a list of databases ...
createdb myNewDB
psql myNewDB
... do stuff with your database ... 
p0
... hopefully concluding with the message ...
server stopped

最终如果想清理:

Note that the data will persist across sessions. If you really want to clean out you whole server, you can use the command:

$ rm -fr /localstorage/$USER/pgsql

Reminder --最后提醒别忘了关机

You must shut down your server at the end of each session with PostgreSQL if you're working on the CSE workstations. Failure to do this means that the next student who uses that workstation may need to adjust their configuration (after first working out what the problem is) in order to start their server.

A Sample Database--一个简单数据库的例子

Once your server is up-and-running, you ought to load up the small sample database (on beers) and try a few queries on its data. This is especially important if you haven't used PostgreSQL before; you need to get used to its interactive interface.

You can set up the beer database as follows:

注意运行前先启动服务器:p1

运行完毕后关闭服务器:p0

$ createdb beer
$ psql beer -f /web/cs9315/24T1/pracs/p01/beer.dump
... around 20 lines include SET, CREATE TABLE, ALTER TABLE...
$ psql beer
SET
psql (15.6)
Type "help" for help.beer=# select count(*) from beers;count
-------24
(1 row)beer=# \d
... gives a list of tables in the database ...... explore/manipulate the database ...
beer=# \q
$

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/386702.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第三方软件测试报告可做哪些用途?

1. 评估软件质量:第三方软件测试报告通过对软件的各项性能指标进行测试和分析,能够客观地评估软件的质量水平。这份报告可以为软件的开发团队提供反馈,帮助他们发现和修复潜在的问题,提高软件的质量和稳定性。 2. 验证软件功能&a…

<数据集>手机识别数据集<目标检测>

数据集格式:VOCYOLO格式 图片数量:16172张 标注数量(xml文件个数):16172 标注数量(txt文件个数):16172 标注类别数:1 标注类别名称:[Phone] 使用标注工具:labelImg 标注规则:…

探索分布式光伏运维系统的组成 需要几步呢?

前言 随着光伏发电的不断发展,对于光伏发电监控系统的需求也日益迫切,“互联网”时代,“互联网”的理念已经转化为科技生产的动力,促进了产业的升级发展,本文结合“互联网”技术提出了一种针对分散光伏发电站运行数据…

c#调用python代码,实现读取npy的数据并显示图像

本例子实现的功能是: 根据stat.npy、ops.npy两个npy文件的内容,显示图形 1. 用python代码实现读取两个文件,文件名为read_npy.py,代码如下: import numpy as npdef read_npy_files(stat_file, ops_file):stat np.lo…

NSL-KDD入侵检测系统的设计与实现系列预告

每日进阶-基于机器学习的入侵检测系统——打怪升级之道 在当今的数字时代,网络安全不仅是防御,更是主动出击。你是否想知道如何用机器学习技术设计一套入侵检测系统(IDS),让黑客无所遁形?本系列文章将为您揭…

【全志H616开发】Linux守护进程

文章目录 守护进程简介基本特点创建一个守护进程通常涉及以下步骤:进程查看指令: 守护进程开发代码示例: 开机自动启动 守护进程 简介 Linux Daemon(守护进程)是运行在后台的一种特殊进程。它独立于控制终端并且周期性…

VScode | 我的常用插件分享

系列文章目录 本系列文章主要分享作位前端开发的工具之------VScode的使用分享。 文章目录 目录 系列文章目录 文章目录 前言 一、Vetur 三、别名路径跳转 四、Prettier 五、koroFileHeader 六、vue-helper 总结 前言 本文主要分享VScode的好用插件。 一、Vetur Vue的Vetur插…

【Vulnhub系列】Vulnhub_Raven2靶场渗透(原创)

【Vulnhub系列靶场】Vulnhub_Raven2 渗透 原文转载已经过授权 原文链接:Lusen的小窝 - 学无止尽,不进则退 (lusensec.github.io) 一、环境准备 从网盘下载该靶机,在vm中选择【打开】 然后设置好存储路径,开机后检查靶机的网络连…

谷粒商城实战笔记-84-商品服务-API-新增商品-获取分类关联的品牌

文章目录 一,品牌查询接口的后台实现二,编码经验总结1,Controller层的作用1.1 参数处理1.2 调用Service1.3 处理Service返回结果实例 2,VO的封装时机3,Service中最好注入Service,不要直接依赖Dao 问题记录 …

vue2 vue3 props 的处理机制

在 Vue 2 中,props 是单向数据流,父组件向子组件传递的 props 默认情况下是不具有响应式特性的。这意味着当父组件的数据发生变化时,如果传递给子组件的 props 发生变化,子组件不会自动更新视图。 具体来说,在 Vue 2 …

增量学习中Task incremental、Domain incremental、Class incremental 三种学习模式的概念及代表性数据集?

1 概念 在持续学习领域,Task incremental、Domain incremental、Class incremental 是三种主要的学习模式,它们分别关注不同类型的任务序列和数据分布变化。 1.1 Task Incremental Learning (Task-incremental) 任务增量学习,也称为任务增…

【论文共读】【翻译】【GAN】Generative Adversarial Nets

论文原文地址:https://arxiv.org/pdf/1406.2661 翻译:Generative Adversarial Nets 生成对抗网络 0. 摘要 提出了一种新的对抗过程估计生成模型的框架,其中我们同时训练两个模型:一个是捕获数据分布的生成模型G,另一…

燃气安全无小事,一双专业劳保鞋让你步步安心!

燃气作为我们日常生活中不可或缺的能源之一,为我们的生活提供了极大便利,其安全性往往被忽视在忙碌的日常生活背后。然而,燃气事故一旦发生,后果往往不堪设想,轻则财产损失,重则危及生命。因此,…

dockerfile部署镜像 ->push仓库 ->虚拟机安装建木 ->自动部署化 (详细步骤)

目录 创建私服仓库 vi /etc/docker/daemon.json vim deploy.sh判断脚本内容 创建 建木 后端部署 命名空间 设置密码用户名 创建git仓库 gitignore文件内容 图形项目操作 git maven docker镜像 点击流程日志 vim /etc/docker/daemon.json 执行部署脚本 ip 开发…

Linux网络——深入理解传入层协议TCP

目录 一、前导知识 1.1 TCP协议段格式 1.2 TCP全双工本质 二、三次握手 2.1 标记位 2.2 三次握手 2.3 捎带应答 2.4 标记位 RST 三、四次挥手 3.1 标记位 FIN 四、确认应答(ACK)机制 五、超时重传机制 六 TCP 流量控制 6.1 16位窗口大小 6.2 标记位 PSH 6.3 标记…

Jackson常用注解详解

Hi 👋, Im shy 有人见尘埃,有人见星辰 Jackson常用注解详解 文章目录 Jackson常用注解详解0. 引入依赖1. JsonProperty2. JsonIgnore3. JsonFormat4. JsonInclude5. JsonCreator6. JsonValue7. JsonIgnoreProperties结论 Jackson是Java生态系统中广泛…

Redis学习[1] ——基本概念和数据类型

Redis学习[1] ——基本概念和数据类型 一、Redis基础概念 1.1 Redis是什么,有什么特点? Redis是一个基于**内存的数据库,因此读写速度非常快**,常用作缓存、消息队列、分布式锁和键值存储数据库。支持多种数据结构:…

大数据与人工智能:数据隐私与安全的挑战_ai 和 数据隐私

前言 1.背景介绍 随着人工智能(AI)和大数据技术的不断发展,我们的生活、工作和社会都在不断变化。这些技术为我们提供了许多好处,但同时也带来了一系列挑战,其中数据隐私和安全是最为关键的之一。数据隐私和安全问题的出现,主要…

分布式锁的三种实现方式:Redis、基于数据库和Zookeeper

分布式锁的实现 操作共享资源:例如操作数据库中的唯一用户数据、订单系统、优惠券系统、积分系统等,这些系统需要修改用户数据,而多个系统可能同时修改同一份数据,这时就需要使用分布式锁来控制访问,防止数据不一致。…

angular入门基础教程(九)依赖注入(DI)

依赖注入 Angular 中的依赖注入(DI)是框架最强大的特性之一。可以将依赖注入视为 Angular 在运行时为你的应用 提供所需资源的能力。依赖项可以是服务或其他资源。 使用服务的一种方式是作为与数据和 API 交互的方式。为了使服务可重用,应该…