Hey @wizkid
It looks like your php-cli command is not using the php.ini you made your changes in. Try the following command, to dynamically assign a memory_limit just for the execution of your script:
sudo -u www-data php -d memory_limit=2048M /var/www/nextcloud/occ db:add-missing-indices
This way you should be able to execute the script in question, without it being killed.
EDIT: This could help as well (OOM when running occ db:add-missing-indices after upgrade to NC 21 - #4 by Dampfklon)