Vous n'êtes pas identifié(e).
Pages : 1
Suite à vos différent message, voici ce que j'ai essayé malheureusement sans succès.
Après de nouvelles recherches, il semblerait que pg_createcluster ne fonctionne pas sous Ubuntu.
cf. https://www.reddit.com/r/PostgreSQL/com … vs_initdb/
Je vais donc tester sans pg_createcluster mais à la place initdb.
Merci à vous
Bonjour,
je suis tout nouveau sur PostgreSQL.
Je souhaite écrire un script qui me permet d'installer PostgreSQL 14 sur Ubuntu et Mac OSX de manière automatique et créer une instance.
Seulement, j'obtiens un message d'erreur suivant sous Mac OSX : "Error: invalid version 'initdb'"
Ci-dessous mon script.
Pourriez vous me dire ce que j'ai loupé dans mon script ?
P.S : j'ai fait des recherches mais ne trouve rien pour m'aider.
Merci d'avance
Script d'installation et de paramétrage automatique :
#!/bin/bash
echo "Installation of PostGreSQL"
pg_version=14
instance_name="DataBase_Test"
username=Toto
# -----------------
# Functions Support
# -----------------
is_file_found(){
[ -f "$1" ] && return $TRUE || return $FALSE
}
string_exists_in_file(){
local line=$1
local file=$2
#if grep -Fxq "$line" $file
#then
# # code if found
#else
# # code if not found
#fi
case `grep -Fx "$line" $file >/dev/null; echo $?` in
0)
# code if found
;;
1)
# code if not found
echo $line >> $file
;;
*)
# code if an error occurred
echo $line " cannot be added to the file " $file
;;
esac
}
pghba_file_add() {
local bdd_name=$2
local user_name=$3
local network_id=$4
local file=$6
# Default value assignement
if [ -z "$1" ]
then
local connexion_type="local"
else
local connexion_type=$1
fi
if [ -z "$5" ]
then
local auth_metho="scram-sha-256"
else
local auth_metho=$5
fi
# Update the pg_hba file
if ! [[ -z "$1" && -z "$2" && -z "$3" && -z "$4" && -z "$5" && -z "$6" ]]
then
string_exists_in_file "$connexion_type $bdd_name $user_name $ $network_id $auth_metho" $file
fi
}
# ---------------------
# Uninstall PostGre SQL
# ---------------------
#which -s psql
#if [ $? -eq 0 ]; then
# # PostGres is installed
# pg_dropcluster --stop $pg_version $instance_name
# if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# echo 'Your computer is running under : Linux'
# sudo apt-get --purge remove postgresql postgresql-doc postgresql-common postgresql-contrib
# elif [[ $OSTYPE == 'darwin'* ]]; then
# echo 'Your computer is running under : macOS'
# #brew remove postgresql postgresql-doc postgresql-common postgresql-contrib
# brew remove postgresql
# brew remove petere/postgresql/postgresql@$pg_version
# brew uninstall postgres
# fi
#else
# # PostGres is not installed
# :
#fi
# ---------------------------------
# Install PostGre SQL avec HomeBrew
# ---------------------------------
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Import the GPG repository key with the commands
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Add the PostgreSQL repository by typing
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ 'lsb_release -cs'-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
# Update the Package List
sudo apt-get update
# Install PostgreSQL
sudo apt-get -y install postgresql postgresql-contrib postgresql-client
# Change Startup settings
sudo systemctl enable postgresql
# Restart PostgreSQL
sudo systemctl restart postgresql
# Check PostgreSQL Port Usage
ss -nlt
# Adjust Firewall Settings
sudo ufw allow from any to any port 5432 proto tcp
elif [[ $OSTYPE == 'darwin'* ]]; then
# Update brew
brew upgrade
brew update
brew doctor
brew install postgresql
#brew install petere/postgresql/postgresql-common
#brew search petere/postgresql
#brew install petere/postgresql/postgresql@$pg_version
# Perl installation
sudo xcode-select --switch /Applications/Xcode.app/
# Launch PostgreSQL
#brew services start postgresql
# Link PostGreSQL
brew link --overwrite postgresql
fi
# ---------------------
# Configure PostGre SQL
# ---------------------
# Define the Directory where the database are stored
read -p "Enter the database directory path: " dbpath
dbpath=${dbpath:-~/postgres/$pg_version/$instance_name}
echo "Repertoire de stockage de la base de données ${dbpath}"
if ! [[ -z "$dbpath" && -d "$dbpath" ]]; then
mkdir -p $dbpath
dbpath_parentdir="$(dirname "$dbpath")"
#chown -R postgres:postgres $dbpath_parentdir
chown -R Toto $dbpath_parentdir
chmod -R 700 $dbpath_parentdir
fi
# Initialisation d'une instance
#initdb -A md5 -E UTF8 -locale=fr_BE -D $dbpath -X $dbpath_parentdir/wals
#pg_createcluster -p 5432 -l "$dbpath_parentdir/postgres-$pg_version" -e UTF8 -locale=fr_BE -d $dbpath -A md5 -X $dbpath_parentdir/wals
#pg_createcluster -p 5432 -l "$dbpath_parentdir/$instance_name" -u $username -e UTF8 -locale=fr_BE -d $dbpath -- initdb -A md5 -X $dbpath_parentdir/wals
pg_createcluster -p 5442 -l "$dbpath_parentdir/$instance_name" -u $username -e UTF-8 --locale=fr_BE -d $dbpath -- initdb -A -X $dbpath_parentdir/wals
# Server Start
#pg_ctl -D (basename {$dbpath}) -l journaltrace start
#pg_ctl -D "$dbpath_parentdir/postgres-$pg_version" -l "$dbpath_parentdir/postgres-$pg_version/server.log" start
pg_ctl -D "$dbpath_parentdir/$instance_name" -l "$dbpath_parentdir/server_$instance_name.log" start
# List instance On-Going
pg_lsclusters
# -----------------------------
# Gestion des Connexions Server
# -----------------------------
session_file="pg_hba.conf"
pg_hba_path="$dbpath_parentdir/$session_file"
# let us call our function
is_file_found $pg_hba_path
# take action based upon return value
if [ $? -eq 0 ]; then
:
else
cat > $pg_hba_path
fi
pghba_file_add "local" $instance_name "postgres" "" "scram-sha-256" $pg_hba_path
pghba_file_add "host" $instance_name "postgres" "0.0.0.0/O" "scram-sha-256" $pg_hba_path
# ---------------------
# Start PostGre SQL
# ---------------------
pg_ctlcluster $pg_version $instance_name start
Pages : 1