Difference between revisions of "Pg ctl - Single Directory Postgres"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
# Download Binaries
 
# Download Binaries
 
- https://www.enterprisedb.com/download-postgresql-binaries
 
- https://www.enterprisedb.com/download-postgresql-binaries
- https://sbp.enterprisedb.com/getfile.jsp?fileid=1257664&_ga=2.199661166.1318609253.1625964422-1196070153.1625964422
+
or source
 +
- https://www.postgresql.org/ftp/source/v13.3/
 +
- https://wiki.postgresql.org/wiki/Compile_and_Install_from_source_code
 +
 
 +
A simple example
 +
```
 +
download(){
 +
  sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc
 +
  curl -LO https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.gz
 +
  tar xf postgresql-13.3.tar.gz
 +
  install_prefix=/pgtest1/pgsql
 +
  mkdir -p $install_prefix
 +
}
 +
 
 +
compile(){
 +
  ./configure
 +
  make
 +
}
 +
 
 +
install(){
 +
  su
 +
  make install prefix=$install_prefix
 +
  adduser postgres
 +
}
 +
 
 +
initdb(){
 +
  mkdir -p $install_prefix/data
 +
  chown -R postgres $install_prefix/data
 +
  sudo -u postgres $install_prefix/bin/initdb -D $install_prefix/data
 +
  sudo -u postgres $install_prefix/bin/pg_ctl -D $install_prefix/data -l $install_prefix/logfile start -o "-F -p 5433"
 +
 
 +
}
 +
 
 +
testdb(){
 +
  # sudo -u postgres $install_prefix/bin/createdb test
 +
  # sudo -u postgres $install_prefix/bin/psql test
 +
  $install_prefix/bin/psql -U postgres -h 127.0.0.1 -p 5433 -c "DROP DATABASE IF EXISTS foo;"
 +
  $install_prefix/bin/psql -U postgres -h 127.0.0.1 -p 5433 -c "CREATE DATABASE foo;"
 +
  # psql -U postgres -h 127.0.0.1 -p 5433 -c "SELECT schema_name FROM information_schema.schemata;"
 +
  # psql -U postgres -h 127.0.0.1 -p 5433 -c "SELECT nspname FROM pg_catalog.pg_namespace;;"
 +
  $install_prefix/bin/psql -U postgres -h 127.0.0.1 -p 5433 -c "\l"
 +
  # pg_dumpall -U postgres -h 127.0.0.1 -p 5433
 +
}
 +
 
 +
download
 +
compile
 +
install
 +
initdb
 +
testdb
 +
```
 +
 
 +
 
 +
# Download and init from binaries on Linux
 +
```
 +
curl --output pgsql.tar.gz -L https://sbp.enterprisedb.com/getfile.jsp?fileid=1257664&_ga=2.131528655.1318609253.1625964422-1196070153.1625964422
 +
tar xf pgsql.tar.gz
 +
sudo mkdir /pg2
 +
cp -rp pgsql /pg2/
 +
sudo chown -R postgres:postgres /pg2
 +
cd /pg2
 +
sudo -u postgres pgsql/bin/pg_ctl -D busk init
 +
sudo -u postgres pgsql/bin/pg_ctl -D busk -l logfile start -o "-F -p 5434"
 +
pgsql/bin/pg_dumpall -U postgres -h 127.0.0.1 -p 5434
 +
pgsql/bin/psql -U postgres -h 127.0.0.1 -p 5434
 +
```
 +
 
  
 
# Run
 
# Run
Line 11: Line 76:
 
psql -U postgres -h 127.0.0.1 -p 5433
 
psql -U postgres -h 127.0.0.1 -p 5433
 
pg_dumpall -U postgres -h 127.0.0.1 -p 5433
 
pg_dumpall -U postgres -h 127.0.0.1 -p 5433
 +
```
 +
 +
# Upgrading - https://www.postgresql.org/docs/current/pgupgrade.html
 +
```
 +
 
```
 
```

Latest revision as of 16:57, 11 July 2021

Download Binaries

A simple example

download(){
  sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc
  curl -LO https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.gz
  tar xf postgresql-13.3.tar.gz
  install_prefix=/pgtest1/pgsql
  mkdir -p $install_prefix
}

compile(){
  ./configure
  make
}

install(){
  su
  make install prefix=$install_prefix
  adduser postgres
}

initdb(){
  mkdir -p $install_prefix/data
  chown -R postgres $install_prefix/data
  sudo -u postgres $install_prefix/bin/initdb -D $install_prefix/data
  sudo -u postgres $install_prefix/bin/pg_ctl -D $install_prefix/data -l $install_prefix/logfile start -o "-F -p 5433"

}

testdb(){
  # sudo -u postgres $install_prefix/bin/createdb test
  # sudo -u postgres $install_prefix/bin/psql test
  $install_prefix/bin/psql -U postgres -h 127.0.0.1 -p 5433 -c "DROP DATABASE IF EXISTS foo;"
  $install_prefix/bin/psql -U postgres -h 127.0.0.1 -p 5433 -c "CREATE DATABASE foo;"
  # psql -U postgres -h 127.0.0.1 -p 5433 -c "SELECT schema_name FROM information_schema.schemata;"
  # psql -U postgres -h 127.0.0.1 -p 5433 -c "SELECT nspname FROM pg_catalog.pg_namespace;;"
  $install_prefix/bin/psql -U postgres -h 127.0.0.1 -p 5433 -c "\l"
  # pg_dumpall -U postgres -h 127.0.0.1 -p 5433
}

download
compile
install
initdb
testdb

Download and init from binaries on Linux

curl --output pgsql.tar.gz -L https://sbp.enterprisedb.com/getfile.jsp?fileid=1257664&_ga=2.131528655.1318609253.1625964422-1196070153.1625964422
tar xf pgsql.tar.gz
sudo mkdir /pg2
cp -rp pgsql /pg2/
sudo chown -R postgres:postgres /pg2
cd /pg2
sudo -u postgres pgsql/bin/pg_ctl -D busk init
sudo -u postgres pgsql/bin/pg_ctl -D busk -l logfile start -o "-F -p 5434"
pgsql/bin/pg_dumpall -U postgres -h 127.0.0.1 -p 5434
pgsql/bin/psql -U postgres -h 127.0.0.1 -p 5434

Run

sudo -u postgres mkdir /pg
cd /pg
sudo -u postgres /usr/lib/postgresql/12/bin/pg_ctl -D busk init
sudo -u postgres /usr/lib/postgresql/12/bin/pg_ctl -D busk -l logfile start -o "-F -p 5433"
psql -U postgres -h 127.0.0.1 -p 5433
pg_dumpall -U postgres -h 127.0.0.1 -p 5433

Upgrading - https://www.postgresql.org/docs/current/pgupgrade.html

<br />