Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to create new PDB from an existing pdb file instead of pdbseed #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions createDatabase
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,46 @@ set -Eeuo pipefail
NEW_PDB="${1:-}"

if [ -n "${NEW_PDB}" ]; then
if [ -f "${ORACLE_BASE}/${NEW_PDB}.pdb" ]; then
echo "Plugging existing pluggable database ${NEW_PDB} from ${ORACLE_BASE}/${NEW_PDB}.pdb"

RANDOM_PDBADIN_PASSWORD=$(date +%s | sha256sum | base64 | head -c 8)
sqlplus -s / as sysdba <<EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE

CREATE PLUGGABLE DATABASE ${NEW_PDB} \
USING '${ORACLE_BASE}/${NEW_PDB}.pdb' COPY \
FILE_NAME_CONVERT=('$ORACLE_BASE','${ORACLE_BASE}/oradata/${ORACLE_SID}/${NEW_PDB}');

exit;
EOF

# remove pdb file same as FREE.7z is removed after initialization
rm -v "${ORACLE_BASE}/${NEW_PDB}.pdb"
else
echo "Creating new pluggable database ${NEW_PDB}"

RANDOM_PDBADIN_PASSWORD=$(date +%s | sha256sum | base64 | head -c 8)
sqlplus -s / as sysdba <<EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE

CREATE PLUGGABLE DATABASE ${NEW_PDB} \
ADMIN USER PDBADMIN IDENTIFIED BY "${RANDOM_PDBADIN_PASSWORD}" \
FILE_NAME_CONVERT=('pdbseed','${NEW_PDB}') \
DEFAULT TABLESPACE USERS \
DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/${NEW_PDB}/users01.dbf' \
SIZE 1m AUTOEXTEND ON NEXT 10m MAXSIZE UNLIMITED;

exit;
EOF
unset RANDOM_PDBADIN_PASSWORD
fi

sqlplus -s / as sysdba <<EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE

CREATE PLUGGABLE DATABASE ${NEW_PDB} \
ADMIN USER PDBADMIN IDENTIFIED BY "${RANDOM_PDBADIN_PASSWORD}" \
FILE_NAME_CONVERT=('pdbseed','${NEW_PDB}') \
DEFAULT TABLESPACE USERS \
DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/${NEW_PDB}/users01.dbf' \
SIZE 1m AUTOEXTEND ON NEXT 10m MAXSIZE UNLIMITED;

-- Open PDB and save state
ALTER PLUGGABLE DATABASE ${NEW_PDB} OPEN READ WRITE;
ALTER PLUGGABLE DATABASE ${NEW_PDB} SAVE STATE;
Expand All @@ -50,6 +76,4 @@ if [ -n "${NEW_PDB}" ]; then
exit;
EOF

unset RANDOM_PDBADIN_PASSWORD

fi;