@@ -8,6 +8,43 @@ trap popd EXIT
8
8
9
9
source ./ephemeral-postgres-config.sh
10
10
11
+ has_no_cow () {
12
+ local file=" $1 "
13
+ [[ " $( lsattr " $file " 2> /dev/null | awk ' {print $1}' ) " == * C* ]]
14
+ }
15
+
16
+ disable_cow () {
17
+ local dir=" $1 "
18
+
19
+ if has_no_cow " $dir " ; then
20
+ echo " Skipping $dir : already has No_COW attribute"
21
+ return
22
+ fi
23
+
24
+ # Set the No_COW attribute on the directory
25
+ chattr +C " $dir "
26
+ if [[ $? -ne 0 ]]; then
27
+ echo " Failed to set +C attribute on $dir "
28
+ exit 1
29
+ fi
30
+
31
+ # Recreate files and directories to ensure +C applies to them
32
+ for file in " $dir " /* ; do
33
+ if [[ -f " $file " ]]; then
34
+ if has_no_cow " $file " ; then
35
+ echo " Skipping $file : already has No_COW attribute"
36
+ else
37
+ echo " Disable CoW on $file "
38
+ mv " $file " " $file .tmp"
39
+ cp --preserve=all " $file .tmp" " $file "
40
+ rm " $file .tmp"
41
+ fi
42
+ elif [[ -d " $file " ]]; then
43
+ disable_cow " $file " # Recursively disable CoW in subdirectories
44
+ fi
45
+ done
46
+ }
47
+
11
48
if [[ " ${EPHEMERAL_POSTGRES_AUTO_UPDATE} " -eq 1 ]]; then
12
49
if git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then
13
50
if [ -z " $( git status --porcelain) " ]; then
@@ -47,6 +84,13 @@ if [ -n "$EPHEMERAL_POSTGRES_DATA_DIR" ]; then
47
84
48
85
EPHEMERAL_POSTGRES_DOCKER_RUN_ARGS+=" -v $EPHEMERAL_POSTGRES_DATA_DIR :/var/lib/postgresql/data"
49
86
echo " Using data directory $EPHEMERAL_POSTGRES_DATA_DIR "
87
+
88
+ # CoW (eg: with btrs) has a bad time with the frequent small writes from postgres
89
+ if [[ " $OSTYPE " =~ ^linux ]]; then
90
+ echo " Disabling CoW (copy on write) in data directory $EPHEMERAL_POSTGRES_DATA_DIR "
91
+ disable_cow " $EPHEMERAL_POSTGRES_DATA_DIR "
92
+ fi
93
+
50
94
else
51
95
if [[ " $OSTYPE " =~ ^linux ]]; then
52
96
echo " Using ram disk"
0 commit comments