設定root密碼,並建立db以及密碼和使用者
Vagrant.configure("2") do |config|
config.vm.box = "oraclelinux/8"
config.vm.network "private_network", ip: "192.168.56.101"
config.vm.hostname = "pg15vm"
config.vm.provider "virtualbox" do |vb|
vb.name = "pg15vm"
vb.memory = "2048" # Set memory to 2GB
vb.cpus = 1 # Set CPU count to 1
end
config.vm.provision "shell", inline: <<-SHELL
# Update the system
sudo dnf update -y
# Reset root password
echo "root:new_password" | sudo chpasswd
# Install PostgreSQL 15 repository
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-8-x86_64/pgdg-oraclelinux15-15-3.noarch.rpm
# Install PostgreSQL 15
sudo dnf install -y postgresql15-server
# Initialize and start PostgreSQL service
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable --now postgresql-15
# Configure PostgreSQL authentication
echo "host all all 0.0.0.0/0 md5" | sudo tee -a /var/lib/pgsql/15/data/pg_hba.conf
sudo systemctl restart postgresql-15
# Create test_user and test_db
sudo -u postgres psql -c "CREATE USER test_user WITH PASSWORD 'test_user';"
sudo -u postgres psql -c "CREATE DATABASE test_db OWNER test_user;"
# Create schema test_c under test_user
sudo -u postgres psql -c "CREATE SCHEMA test_c AUTHORIZATION test_user;"
SHELL
end