Skip to content
logo
Percona Server for MongoDB 4.2
Percona Memory Engine
Initializing search
    percona/psmdb-docs
    percona/psmdb-docs
    • Home
    • Percona Server for MongoDB feature comparison
      • Overview
      • Install Percona Server for MongoDB on Debian and Ubuntu
      • Install Percona Server for MongoDB on Red Hat Enterprise Linux and derivatives
      • Install Percona Server for MongoDB from binary tarball
      • Run Percona Server for MongoDB in a Docker container
        • Percona Memory Engine
          • Usage
          • Configuration
            • Options
          • Switching storage engines
            • Considerations
            • Procedure
            • Data at Rest Encryption
        • Hot Backup
        • $backupCursor and $backupCursorExtend aggregation stages
        • Authentication
        • Enable authentication
        • Set up LDAP authentication with SASL
        • Set up x.509 authentication and LDAP authorization
        • Setting up Kerberos authentication
        • LDAP authorization
        • Set up LDAP authentication and authorization using NativeLDAP
        • Data at rest encryption
        • HashiCorp Vault integration
        • Using the Key Management Interoperability Protocol (KMIP)
        • Local key management using a keyfile
        • Migrate from key file encryption to HashiCorp Vault encryption
      • Auditing
      • Profiling rate limit
      • Log redaction
      • Additional text search algorithm - ngram
      • Tune parameters
        • Upgrade from 4.0 to 4.2
        • Upgrade Percona Server for MongoDB
      • Uninstall Percona Server for MongoDB
      • Release notes index
      • Percona Server for MongoDB 4.2.24-24 (2023-03-09)
      • Percona Server for MongoDB 4.2.23-23 (2022-11-08)
      • Percona Server for MongoDB 4.2.22-22 (2022-09-06)
      • Percona Server for MongoDB 4.2.21-21 (2022-06-29)
      • Percona Server for MongoDB 4.2.20-20 (2022-05-23)
      • Percona Server for MongoDB 4.2.19-19 (2022-03-29)
      • Percona Server for MongoDB 4.2.18-18 (2022-01-19)
      • Percona Server for MongoDB 4.2.17-17 (2021-10-11)
      • Percona Server for MongoDB 4.2.15-16 (2021-07-26)
      • Percona Server for MongoDB 4.2.14-15 (2021-05-13)
      • Percona Server for MongoDB 4.2.13-14 (2021-04-01)
      • Percona Server for MongoDB 4.2.12-13 (2021-02-03)
      • Percona Server for MongoDB 4.2.11-12 (2020-12-07)
      • Percona Server for MongoDB 4.2.10-11 (2020-11-02)
      • Percona Server for MongoDB 4.2.9-10 (2020-10-09)
      • Percona Server for MongoDB 4.2.9-9 (2020-09-03)
      • Percona Server for MongoDB 4.2.8-8 (2020-07-07)
      • Percona Server for MongoDB 4.2.7-7 (2020-06-04)
      • Percona Server for MongoDB 4.2.6-6 (2020-05-07)
      • Percona Server for MongoDB 4.2.5-5 (2020-04-02)
      • Percona Server for MongoDB 4.2.3-4 (2020-02-20)
      • Percona Server for MongoDB 4.2.2-3 (2019-12-24)
      • Percona Server for MongoDB 4.2.1-1 (2019-11-13)
      • Percona Server for MongoDB 4.2.0-1 (2019-09-09)
    • Glossary
      • Copyright and Licensing Information
      • Trademark Policy

    • Usage
    • Configuration
      • Options
    • Switching storage engines
      • Considerations
      • Procedure
      • Data at Rest Encryption

    Percona Memory Engine¶

    Percona Memory Engine is a special configuration of WiredTiger that does not store user data on disk. Data fully resides in the main memory, making processing much faster and smoother. Keep in mind that you need to have enough memory to hold the data set, and ensure that the server does not shut down.

    The Percona Memory Engine is available in Percona Server for MongoDB along with the default MongoDB engine WiredTiger.

    Usage¶

    As of version 3.2, Percona Server for MongoDB runs with WiredTiger by default. You can select a storage engine using the --storageEngine command-line option when you start mongod. Alternatively, you can set the storage.engine variable in the configuration file (by default, /etc/mongod.conf):

    storage:
      dbPath: <dataDir>
      engine: inMemory
    

    Configuration¶

    You can configure Percona Memory Engine using either command-line options or corresponding parameters in the /etc/mongod.conf file. The following are the configuration examples:

    The configuration file is formatted in YAML

    storage:
      engine: inMemory
      inMemory:
        engineConfig:
          inMemorySizeGB: 140
          statisticsLogDelaySecs: 0
    

    Setting parameters in the configuration file is the same as starting the mongod daemon with the following options:

    mongod --storageEngine=inMemory \
    --inMemorySizeGB=140 \
    --inMemoryStatisticsLogDelaySecs=0
    

    Options¶

    The following options are available (with corresponding YAML configuration file parameters):

    Command line Configuration file Default Description
    --inMemorySizeGB() storage.inMemory.engineConfig.inMemorySizeGB 50% of total memory minus 1024 MB, but not less than 256 MB Specifies the maximum memory in gigabytes to use for data
    --inMemoryStatisticsLogDelaySecs() storage.inMemory.engineConfig.statisticsLogDelaySecs 0 Specifies the number of seconds between writes to statistics log. If 0 is specified then statistics are not logged

    Switching storage engines¶

    Considerations¶

    If you have data files in your database and want to change to Percona Memory Engine, consider the following:

    • Data files created by one storage engine are not compatible with other engines, because each one has its own data model.

    • When changing the storage engine, the mongod node requires an empty dbPath data directory when it is restarted. Though Percona Memory Engine stores all data in memory, some metadata files, diagnostics logs and statistics metrics are still written to disk. This is controlled with the --inMemoryStatisticsLogDelaySecs option.

    Creating a new dbPath data directory for a different storage engine is the simplest solution. Yet when you switch between disk-using storage engines (e.g. from WiredTiger to Percona Memory Engine), you may have to delete the old data if there is not enough disk space for both. Double-check that your backups are solid and/or the replica set nodes are healthy before you switch to the new storage engine.

    Procedure¶

    To change a storage engine, you have the following options:

    Temporarily test Percona Memory Engine¶

    Set a different data directory for the dbPath variable in the configuration file. Make sure that the user running mongod has read and write permissions for the new data directory.

    1. Stop mongod

      $ service mongod stop
      
    2. Edit the configuration file

      storage:
        dbPath: <newDataDir>
        engine: inmemory
      
    3. Start mongod

      $ service mongod start
      

    Permanent switch to Percona Memory Engine without any valuable data in your database¶

    Clean out the dbPath data directory (by default, /var/lib/mongodb) and edit the configuration file:

    1. Stop mongod

      $ service mongod stop
      
    2. Clean out the dbPath data directory

      $ sudo rm -rf <dbpathDataDir>
      
    3. Edit the configuration file

      storage:
        dbPath: <newDataDir>
        engine: inmemory
      
    4. Start mongod

      $ service mongod start
      

    Switch to Percona Memory Engine with data migration and compatibility¶

    For a standalone instance or a single-node replica set, use the mongodump and mongorestore utilities:

    1. Export the dataDir contents

      $ mongodump --out <dumpDir>
      
    2. Stop mongod

      $ service mongod stop
      
    3. Clean out the dbPath data directory

      $ sudo rm -rf <dbpathDataDir>
      
    4. Update the configuration file by setting the new value for the storage.engine variable. Set the engine-specific settings such as storage.inMemory.engineConfig.inMemorySizeGB

    5. Start mongod

      $ service mongod start
      
    6. Restore the database

      $ mongorestore <dumpDir>
      

    Use the “rolling restart” process.

    1. Switch to the Percona Memory Engine on the secondary node. Clean out the dbPath data directory and edit the configuration file:

    2. Stop mongod

      $ service mongod stop
      
    3. Clean out the dbPath data directory

      $ sudo rm -rf <dbpathDataDir>
      
    4. Edit the configuration file

      storage:
        dbPath: <newDataDir>
        engine: inmemory
      
    5. Start mongod

      $ service mongod start
      
    6. Wait for the node to rejoin with the other nodes and report the SECONDARY status.

    7. Repeat the procedure to switch the remaining nodes to Percona Memory Engine.

    Data at Rest Encryption¶

    Using Data at Rest Encryption means using the same storage.\* configuration options as for WiredTiger. To change from normal to Data at Rest Encryption mode or backward, you must clean up the dbPath data directory, just as if you change the storage engine. This is because mongod cannot convert the data files to an encrypted format ‘in place’. It must get the document data again either via the initial sync from another replica set member, or from imported backup dump.

    Contact Us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: December 8, 2022
    Created: December 8, 2022
    Percona LLC and/or its affiliates, © 2023
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.