[Magisk] jcmm11:
What I know is that you need a sleep command.

What I think is happening is that since Pie on the Pixel 3's is using file based encryption it takes a few seconds for the decryption to take place and all the files to be recognized. (This is only an issue at initial boot)

Assuming you're using a service.d script you need about 10 seconds after boot-completed, or about 20 seconds if you don't check for boot completion. Here's some results of a test script:

Script was run twice, once with the boot completion active, once with it commented out. Initial value on the file is 660.

Script:

#!/system/bin/sh
#
#until [ "$(getprop sys.boot_completed)" = 1 ]
# do
# sleep 1
# done
#
Log='/data/local/chmod.log'
Error='/data/local/chmod-error.log'
#

rm -f $Log $Error
#
echo "sleep 0"|tee $Log >$Error
echo "chmod 440"|tee -a $Log >>$Error
chmod 440 /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
ls -l /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
echo "chmod 660"|tee -a $Log >>$Error
chmod 660 /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
ls -l /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error

sleep 10
echo "sleep 10"|tee -a $Log >>$Error
echo "chmod 440"|tee -a $Log >>$Error
chmod 440 /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
ls -l /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
echo "chmod 660"|tee -a $Log >>$Error
chmod 660 /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
ls -l /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error

sleep 10
echo "sleep 20"|tee -a $Log >>$Error
echo "chmod 440"|tee -a $Log >>$Error
chmod 440 /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
ls -l /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
echo "chmod 660"|tee -a $Log >>$Error
chmod 660 /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
ls -l /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error

sleep 10
echo "sleep 30"|tee -a $Log >>$Error
echo "chmod 440"|tee -a $Log >>$Error
chmod 440 /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
ls -l /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
echo "chmod 660"|tee -a $Log >>$Error
chmod 660 /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
ls -l /data/data/com.google.android.gms/databases/dg.db >>$Log 2>>$Error
exit

Results without boot completion check:

chmod.log

sleep 0
chmod 440
chmod 660
sleep 10
chmod 440
chmod 660
sleep 20
chmod 440
-r--r----- 1 u0_a34 u0_a34 5189632 Jul 9 00:04 /data/data/com.google.android.gms/databases/dg.db
chmod 660
-rw-rw---- 1 u0_a34 u0_a34 5189632 Jul 9 00:04 /data/data/com.google.android.gms/databases/dg.db
sleep 30
chmod 440
-r--r----- 1 u0_a34 u0_a34 5189632 Jul 9 00:04 /data/data/com.google.android.gms/databases/dg.db
chmod 660
-rw-rw---- 1 u0_a34 u0_a34 5189632 Jul 9 00:04 /data/data/com.google.android.gms/databases/dg.db

chmod-error.log

sleep 0
chmod 440
chmod: /data/data/com.google.android.gms/databases/dg.db: No such file or directory
ls: /data/data/com.google.android.gms/databases/dg.db: No such file or directory
chmod 660
chmod: /data/data/com.google.android.gms/databases/dg.db: No such file or directory
ls: /data/data/com.google.android.gms/databases/dg.db: No such file or directory
sleep 10
chmod 440
chmod: /data/data/com.google.android.gms/databases/dg.db: No such file or directory
ls: /data/data/com.google.android.gms/databases/dg.db: No such file or directory
chmod 660
chmod: /data/data/com.google.android.gms/databases/dg.db: No such file or directory
ls: /data/data/com.google.android.gms/databases/dg.db: No such file or directory
sleep 20
chmod 440
chmod 660
sleep 30
chmod 440
chmod 660

Results with the boot completion check on were the same, except with a 10 second difference.