Uniaxial pressure provides an efficient approach to control charge density waves in YBa2Cu3Oy. It can enhance the correlation volume of ubiquitous short-range two-dimensional charge-density-wave correlations, and induces a long-range three-dimensional charge density wave, otherwise only accessible at large magnetic fields. Here, we use x-ray diffraction to study the strain dependence of these charge density waves and uncover direct evidence for a form of competition between them. We show that this interplay is qualitatively described by including strain effects in a nonlinear sigma model of competing superconducting and charge-density-wave orders. Our analysis suggests that strain stabilizes the 3D charge density wave in the regions between disorder-pinned domains of 2D charge density waves, and that the two orders compete at the boundaries of these domains. No signatures of discommensurations nor of pair density waves are observed. From a broader perspective, our results underscore the potential of strain tuning as a powerful tool for probing competing orders in quantum materials.