ubuntu 18 虛擬機安裝(4)安裝 postgres sql 數據庫

ubuntu 18 虛擬機安裝(4)安裝 postgres sql 數據庫

如何查看PostgreSQL的版本
https://blog.csdn.net/lee_vincent1/article/details/138731465
postgres 查看全部數據庫
https://blog.csdn.net/xie__jin__cheng/article/details/138653002
Ubuntu18.04安裝Postgresql與配置
https://blog.csdn.net/b285795298/article/details/130759531

https://www.postgresql.org/download/linux/ubuntu/

https://www.cnblogs.com/xu360/articles/16860260.html
How To Install and Use PostgreSQL on Ubuntu 18.04
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04

postgres新增用戶、創建新庫
https://blog.csdn.net/qq_34322136/article/details/135624871
https://www.jb51.net/article/204207.htm

2.設置數據庫時間和時區
(1). 通過命令
PRC為東八區 北京時間 UTC+8
Asia/Shanghai為東八區 上海時間 GMT+8
但是通過這種方式設置時區是session級別的,退出會話會失效

https://blog.csdn.net/qq_45658339/article/details/124431612

查看所有用戶

cat /etc/passwd

查看所有用戶個數

cat /etc/passwd | wc -l
31

sudo apt-get update
sudo apt-get install postgresql -y

The following additional packages will be installed:libpq5 libsensors4 postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common ssl-cert sysstat
Suggested packages:lm-sensors postgresql-doc locales-all postgresql-doc-10 libjson-perl openssl-blacklist isag
The following NEW packages will be installed:libpq5 libsensors4 postgresql postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common ssl-cert sysstat
0 upgraded, 9 newly installed, 0 to remove and 45 not upgraded.
Adding user postgres to group ssl-cert
Creating config file /etc/postgresql-common/createcluster.conf with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.
Setting up libsensors4:amd64 (1:3.4.0-4ubuntu0.1) ...
Setting up postgresql-client-10 (10.23-0ubuntu0.18.04.2) ...
update-alternatives: using /usr/share/postgresql/10/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up sysstat (11.6.1-1ubuntu0.2) ...Creating config file /etc/default/sysstat with new version
update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.service.
Setting up postgresql-10 (10.23-0ubuntu0.18.04.2) ...
Creating new PostgreSQL cluster 10/main ...
/usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/10/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /var/lib/postgresql/10/main ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Asia/Shanghai
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... okSuccess. You can now start the database server using:/usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile startVer Cluster Port Status Owner    Data directory              Log file
10  main    5432 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
update-alternatives: using /usr/share/postgresql/10/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
Setting up postgresql (10+190ubuntu0.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for libc-bin (2.27-3ubuntu1.5) ...
Processing triggers for systemd (237-3ubuntu10.57) ...

sudo systemctl status postgresql
sudo systemctl start postgresql
sudo systemctl stop postgresql

postgresql.service - PostgreSQL RDBMSLoaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)Active: active (exited) since Thu 2024-06-27 14:29:57 CST; 10min agoMain PID: 2387 (code=exited, status=0/SUCCESS)Tasks: 0 (limit: 4623)CGroup: /system.slice/postgresql.serviceJun 27 14:29:57 jack systemd[1]: Starting PostgreSQL RDBMS...
Jun 27 14:29:57 jack systemd[1]: Started PostgreSQL RDBMS.

psql --version

psql (PostgreSQL) 10.23 (Ubuntu 10.23-0ubuntu0.18.04.2)

在Ubuntu中安裝Postgresql之后,會自動注冊服務,并隨操作系統自動啟動。
在Ubuntu中安裝Postgresql之后,會自動添加一個postgresql的操作系統的用戶,密碼是隨機的。并且會自動生成一個名字為postgresql的數據庫,用戶名也是postgresql,密碼也是隨機的。
用postgres用戶登錄:

sudo -u postgres psql

或者是

sudo su - postgres
psql

修改PostgresSQL數據庫配置

vi /etc/postgresql/10/main/postgresql.conf

1.1 修改配置文件

vi /etc/postgresql/10/main/postgresql.conf

1.監聽任何地址訪問,修改連接權限

#listen_addresses = 'localhost' 改為 
listen_addresses = '*'

2.啟用密碼驗證

#password_encryption = md5		# md5 or scram-sha-256
password_encryption = md5		# md5 or scram-sha-256
#shared_preload_libraries = ''		# (change requires restart)
shared_preload_libraries = 'timescaledb'		# (change requires restart)
  1. 時區這個不確定 要不要修改
log_timezone = 'Asia/Shanghai'
log_timezone = 'PRC'
  1. 時區不確定要不要修改
timezone = 'Asia/Shanghai'
timezone = 'PRC'

sudo vi /etc/postgresql/10/main/pg_hba.conf


# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               md5

Ubuntu的默認軟件包存儲庫中沒有TimescaleDB,因此在此步驟中,您將從TimescaleDB Personal Packages Archive(PPA)安裝它。

First, add Timescale’s APT repository:

首先,添加Timescale的APT存儲庫:

sudo add-apt-repository ppa:timescale/timescaledb-ppa

Confirm this action by hitting the ENTER key.

通過按ENTER鍵確認此操作。

Next, refresh your APT cache to update your package lists:

接下來,刷新您的APT緩存以更新您的軟件包列表:

sudo apt update

sudo apt install timescaledb-postgresql-10

現在已安裝TimescaleDB并準備使用它。 接下來,您將打開它并在PostgreSQL配置文件中調整與它相關聯的一些設置以優化數據庫。

添加用戶

執行這句話的時候,一定要注意查看,當前是否是測試環境
drop role jack ;
create user jack with password '12345' superuser;
select * from pg_user; 

111

https://blog.csdn.net/ctypyb2002/article/details/79881745

pg_dump -h 127.0.0.1 -U jack-d abc -f abc_bak_2024_06_28.sql

out

Password: 
pg_dump: NOTICE: there are circular foreign-key constraints on this table:
pg_dump:   hypertable
pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
pg_dump: NOTICE: there are circular foreign-key constraints on this table:
pg_dump:   chunk
pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/37185.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/37185.shtml
英文地址,請注明出處:http://en.pswp.cn/web/37185.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

數據資產鑄就市場競爭優勢:運用先進的數據分析技術,精準把握市場脈搏,構建獨特的競爭優勢,助力企業實現市場領先地位,贏得持續成功

目錄 一、引言 二、數據資產的重要性 三、先進數據分析技術的應用 1、大數據分析技術 2、人工智能與機器學習 3、數據可視化技術 四、精準把握市場脈搏 1、深入了解客戶需求 2、預測市場趨勢 3、優化資源配置 五、構建獨特的競爭優勢 1、定制化產品和服務 2、精準營…

數據結構—判斷題

1.數據的邏輯結構說明數據元素之間的順序關系,它依賴于計算機的存儲結構。 答案:錯誤 2.(neuDS)在順序表中邏輯上相鄰的元素,其對應的物理位置也是相鄰的。 答案:正確 3.若一個棧的輸入序列為{1, 2, 3, 4, 5},則不…

nginx上傳文件限制

默認限制 Nginx 限制文件大小可以通過 client_max_body_size 指令來設置,該指令通常在 http、server 或 location 塊中設置,如果不設置,默認上傳大小為1M。 修改上傳文件限制 要修改Nginx的文件上傳大小限制,你需要編輯Nginx的配…

接口自動化測試關聯token的方法?

引言: 在接口自動化測試中,有時候我們需要關聯token來進行身份驗證或權限管理。本文將從零開始,介紹如何詳細且規范地實現接口自動化測試中token的關聯。 步驟一:準備工作 在開始之前,我們需要確保以下準備工作已完成…

如何在 Linux 中后臺運行進程?

一、后臺進程 在后臺運行進程是 Linux 系統中的常見要求。在后臺運行進程允許您在進程獨立運行時繼續使用終端或執行其他命令。這對于長時間運行的任務或當您想要同時執行多個命令時特別有用。 在深入研究各種方法之前,讓我們先了解一下什么是后臺進程。在 Linux 中…

Kafka~特殊技術細節設計:分區機制、重平衡機制、Leader選舉機制、高水位HW機制

分區機制 Kafka 的分區機制是其實現高吞吐和可擴展性的重要特性之一。 Kafka 中的數據具有三層結構,即主題(topic)-> 分區(partition)-> 消息(message)。一個 Kafka 主題可以包含多個分…

3-linux命令行與基本命令

目錄 什么是shell linux命令 命令組成 幾個簡單的命令 linux文件系統導航 什么是shell linux學習路徑:學習shell→配置和環境→見任務和主要工具→編寫shell腳本 shell是一個接收由鍵盤輸入的命令,并將其傳遞給操作系統來執行的程序。幾乎所有…

C++學習全教程(Day2)

一、數組 在程序中為了處理方便,常常需要把具有相同類型的數據對象按有序的形式排列起來,形成“一組”數據,這就是“數組”(array) 數組中的數據,在內存中是連續存放的,每個元素占據相同大小的空間,就像排…

【Spring】DAO 和 Repository 的區別

DAO 和 Repository 的區別 1.概述2.DAO 模式2.1 User2.2 UserDao2.3 UserDaoImpl 3.Repository 模式3.1 UserRepository3.2 UserRepositoryImpl 4.具有多個 DAO 的 Repository 模式4.1 Tweet4.2 TweetDao 和 TweetDaoImpl4.3 增強 User 域4.4 UserRepositoryImpl 5.比較兩種模式…

ISO 19110操作要求類中的/req/operation/formal-definition詳細解釋

/req/operation/formal-definition 要求: 每個要素操作實體必須具有一個形式定義(formal definition),該定義應明確描述操作的行為和影響。 具體解釋 定義 要素操作實體(feature operation entity):這…

深度學習基準模型Mamba

深度學習基準模型Mamba Mamba(英文直譯:眼鏡蛇)具有選擇性狀態空間的線性時間序列建模,是一種先進的狀態空間模型 (SSM),專為高效處理復雜的數據密集型序列而設計。 Mamba是一種深度學習基準模型,專為處理長序列數據而設計&…

【鴻蒙學習筆記】位置設置

官方文檔:位置設置 目錄標題 align:子元素的對齊方式direction:官方文檔沒懂,看圖理解吧 align:子元素的對齊方式 Stack() {Text(TopStart)}.width(90%).height(50).backgroundColor(0xFFE4C4).align(Alignment.TopS…

<Python><ffmpeg>基于python使用PyQt5構建GUI實例:音頻格式轉換程序(MP3/aac/wma/flac)(優化版2)

前言 本文是基于python語言使用pyqt5來構建的GUI,功能是使用ffmpeg來對音頻文件進行格式轉換,如mp3、aac、wma、flac等音樂格式。 UI示例: 環境配置 系統:windows 平臺:visual studio code 語言:python 庫:pyqt5、ffmpeg 概述 本文是建立在之前的博文的基礎上的優化版…

在線教育項目(一):如何防止一個賬號多個地方登陸

使用jwt做驗證,使用賬號作為redis中的key,登錄的時候生成token放到redis中,每次申請資源的時候去看token 有沒有變,因為token每次登錄都會去覆蓋,只要第二次登錄token就不一樣了

Day7:.翻轉字符串里的單詞 151 卡碼網:55.右旋轉字符串

題目 151. 反轉字符串中的單詞 - 力扣&#xff08;LeetCode&#xff09; class Solution { public:// 移除多余空格void moveSpace(string& s) {// 定義快慢指針int slow 0;int fast 0;// 刪除前導空格while (s.size() > 0 && fast < s.size() &&…

【算法——雙指針前綴和】

例題&#xff1a; 奇偶排序數組&#xff08;與下標對應&#xff09; 奇數偶數個數相等 922. 按奇偶排序數組 II #include<iostream> #include<vector> #include<algorithm> using namespace std;int main() {vector<int>nums { 4,2,5,7 };//指針x…

==和equals的區別(面試題)

和equals有什么區別 對于基本數據類型&#xff0c;比較的是值是否相等&#xff0c;對于引用類型則是比較的地址是否相等&#xff1b;對于equals來說&#xff0c;基本數據類型沒有equals方法&#xff0c;對于引用類型equals比較的是引用對象是否相同 那針對以上結論&#xff0c…

西點領導力:卓越是怎樣練成的

今天剛看了一個美國西點軍校第50任校長&#xff1a;羅伯克卡斯倫的《為什么跟西點軍校學領導力培養》這個演講。從中受益良多&#xff0c;于是我就去了解了一下這位校長以及西點軍校。 西點軍校 西點軍校&#xff08;United States Military Academy, USMA&#xff09;&#…

Android常用加解密算法總結

Android開發中對于數據的傳輸和保存一定會使用加密技術&#xff0c;加密算法是最普遍的安保手段&#xff0c;多數情況數據加密后在需要使用源數據時需要再進行解密&#xff0c;但凡是都有例外。下面從可逆加密、不可逆、不純粹加密三種方式記錄一下常見的加解密算法。 加密技術…