第一阶段-编译安装:1,从postgresql官网下载postgresql-9.1.3.tar.bz2这个我想大家都知道的2,把源代码复制到/usr/src/postgres
前言:本人机器:AMD64x2 4400++ 1G 内存
第一阶段-编译安装:
1,从postgresql官网下载postgresql-9.1.3.tar.bz2这个我想大家都知道的
2,把源代码复制到/usr/src/postgresql-9.1.3.tar.bz2 且 cd /usr/src
3,解压: tar xjvf postgresql-9.1.3.tar.bz2
4,进入源码目录: cd postgresql-9.1.3
5,建立pgsql安装目录。这里我选择 :mkdir /usr/pgsql-9.1.3
6,安装必须的工具执行:aptitude install build-essential zlib1g-dev libpam0g-dev libssl-dev libperl-dev kernel-package libncurses5-dev flex bison gawk chkconfig系统会自动安装所以来的软件
7,在源码目录里面执行下面命令:
./configure CFLAGS='-DLINUX_OOM_ADJ=0 -O2 -pipe -march=athlon64 -fomit-frame-pointer -fstack-protector' --prefix=/usr/pgsql-9.1.3 --with-perl --with-openssl --with-pam --enable-nls --disable-debug
8,开始编译 :make -j 4
9,变成成功后,执行 make install 安装
10,,建立postgresql数据库专用普通权限用户 :adduser psqlroot
11,切换到安装目录: cd /usr/pgsql-9.1.3建立初始化数据库集群文件夹:mkdir date
12,改变date所有权限 chown psqlroot:psqlroot date
13,执行数据库初始化(必须使用psqlroot用户):su - psqlroot -c './initdb /usr/pgsql-9.1.3/date'
14,好了,进入date目录可以看到初始化后的文件,比如conf配置文件等等。
第二阶段-制作启动脚本:
1,从源代码目录里面复制出原始的开机脚本:
cp /usr/src/postgresql-9.1.3/contrib/start-scripts/linux /etc/init.d/postgresql
2,给予执行权限:chmod 700 /etc/init.d/postgresql
3,建立s 2 3 4 5 6各个级别启动连接在(/etc/rcS.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d)
使用:chkconfig /etc/init.d/postgresql自动建立 呵呵很方便哦!
4,修改/etc/init.d/postgresql文件,这个文件是用/bin/sh基础的,改成/bin/bash的:
#! /bin/bash
# chkconfig: 2345 98 02
# description: PostgreSQL RDBMS
# This is an example of a start/stop script for SysV-style init, such
# as is used on Linux systems. You should edit some of the variables
# and maybe the 'echo' commands.
#
# Place this file at /etc/init.d/postgresql (or
# /etc/rc.d/init.d/postgresql) and make symlinks to
# /etc/rc.d/rc0.d/K02postgresql
# /etc/rc.d/rc1.d/K02postgresql
# /etc/rc.d/rc2.d/K02postgresql
# /etc/rc.d/rc3.d/S98postgresql
# /etc/rc.d/rc4.d/S98postgresql
# /etc/rc.d/rc5.d/S98postgresql
# Or, if you have chkconfig, simply:
# chkconfig --add postgresql
#
# Proper init scripts on Linux systems normally require setting lock
# and pid files under /var/run as well as reacting to network
# settings, so you should treat this with care.
# Original author: Ryan Kirkpatrick
# contrib/start-scripts/linux
## EDIT FROM HERE
# Installation PREFIX
PREFIX=/usr/pgsql-9.1.3
# Data directory
PGDATA=$PREFIX/date
# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=psqlroot
# Where to keep a log file
PGLOG=/var/log/serverlog
# It's often a good idea to protect the postmaster from being killed by the
# OOM killer (which will tend to preferentially kill the postmaster because
# of the way it accounts for shared memory). Setting the OOM_ADJ value to
# -17 will disable OOM kill altogether. If you enable this, you probably want
# to compile PostgreSQL with "-DLINUX_OOM_ADJ=0", so that individual backends
# can still be killed by the OOM killer.
OOM_ADJ=-17
## STOP EDITING HERE
# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# What to use to start up the postmaster. (If you want the script to wait
# until the server has started, you could use "pg_ctl start -w" here.
# But without -w, pg_ctl adds no value.)
DAEMON="$PREFIX/bin/postmaster"
# What to use to shut down the postmaster
PGCTL="$PREFIX/bin/pg_ctl"
set -e
# Only start if we can find the postmaster.
test -x $DAEMON ||
{
echo "$DAEMON not found"
if [ "$1" = "stop" ]
then exit 0
else exit 5
fi
}
# Parse command line parameters.
case $1 in
start)
echo -n "Starting PostgreSQL: "
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
su - $PGUSER -c "$DAEMON -D $PGDATA &" >>$PGLOG 2>&1
echo "ok"
;;
stop)
echo -n "Stopping PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
reload)
echo -n "Reload PostgreSQL: "
su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
echo "ok"
;;
status)
su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
;;
*)
# Print help
echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
exit 1
;;
esac
exit 0
5,注意上文提到的OOM_ADJ=-17 是为了逃避OOM自动封杀,OK!执行/etc/init.d/postgresql start stop restart 等等命令试试,大工告成!!
6,把安装目录中的conf配置文件复制到/etc/postgresql下面去,方便以后更改配置
mkdir /etc/postgresql
mv /usr/pgsql-9.1.3/date/*conf /etc/postgresql/
cd /usr/pgsql-9.1.3/date
su - psqlroot -c 'ln -s /etc/postgresql/pg_hba.conf pg_hba.conf'
su - psqlroot -c 'ln -s /etc/postgresql/pg_ident.conf pg_ident.conf'
su - psqlroot -c 'ln -s /etc/postgresql/postgresql.conf postgresql.conf'
第三阶段-优化

ACID屬性包括原子性、一致性、隔離性和持久性,是數據庫設計的基石。 1.原子性確保事務要么完全成功,要么完全失敗。 2.一致性保證數據庫在事務前後保持一致狀態。 3.隔離性確保事務之間互不干擾。 4.持久性確保事務提交後數據永久保存。

MySQL既是數據庫管理系統(DBMS),也與編程語言緊密相關。 1)作為DBMS,MySQL用於存儲、組織和檢索數據,優化索引可提高查詢性能。 2)通過SQL與編程語言結合,嵌入在如Python中,使用ORM工具如SQLAlchemy可簡化操作。 3)性能優化包括索引、查詢、緩存、分庫分錶和事務管理。

MySQL使用SQL命令管理數據。 1.基本命令包括SELECT、INSERT、UPDATE和DELETE。 2.高級用法涉及JOIN、子查詢和聚合函數。 3.常見錯誤有語法、邏輯和性能問題。 4.優化技巧包括使用索引、避免SELECT*和使用LIMIT。

MySQL是一種高效的關係型數據庫管理系統,適用於存儲和管理數據。其優勢包括高性能查詢、靈活的事務處理和豐富的數據類型。實際應用中,MySQL常用於電商平台、社交網絡和內容管理系統,但需注意性能優化、數據安全和擴展性。

SQL和MySQL的關係是標準語言與具體實現的關係。 1.SQL是用於管理和操作關係數據庫的標準語言,允許進行數據的增、刪、改、查。 2.MySQL是一個具體的數據庫管理系統,使用SQL作為其操作語言,並提供高效的數據存儲和管理。

InnoDB使用redologs和undologs確保數據一致性和可靠性。 1.redologs記錄數據頁修改,確保崩潰恢復和事務持久性。 2.undologs記錄數據原始值,支持事務回滾和MVCC。

EXPLAIN命令的關鍵指標包括type、key、rows和Extra。 1)type反映查詢的訪問類型,值越高效率越高,如const優於ALL。 2)key顯示使用的索引,NULL表示無索引。 3)rows預估掃描行數,影響查詢性能。 4)Extra提供額外信息,如Usingfilesort提示需要優化。

Usingtemporary在MySQL查詢中表示需要創建臨時表,常見於使用DISTINCT、GROUPBY或非索引列的ORDERBY。可以通過優化索引和重寫查詢避免其出現,提升查詢性能。具體來說,Usingtemporary出現在EXPLAIN輸出中時,意味著MySQL需要創建臨時表來處理查詢。這通常發生在以下情況:1)使用DISTINCT或GROUPBY時進行去重或分組;2)ORDERBY包含非索引列時進行排序;3)使用複雜的子查詢或聯接操作。優化方法包括:1)為ORDERBY和GROUPB


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SublimeText3漢化版
中文版,非常好用

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),